Skip to content

Commit

Permalink
Merge pull request duartegroup#145 from duartegroup/v1.2.3
Browse files Browse the repository at this point in the history
v1.2.3
  • Loading branch information
t-young31 authored Jun 5, 2022
2 parents 239d9fb + 972a22d commit d59fab9
Show file tree
Hide file tree
Showing 41 changed files with 776 additions and 260 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ tests/__pycache__/

tests/*.xyz

**/tmp.xyz

autode/conformers/__pycache__/

autode/transition_states/__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ additional documentation.
## Development

There is a [slack workspace](https://autodeworkspace.slack.com) for development and discussion - please
[email](mailto:[email protected]?subject=autodE%20slack) to be added. Pull requests are
[email](mailto:[email protected]?subject=autodE%20slack) to be added. Pull requests are
very welcome but must pass all the unit tests prior to being merged. Please write code and tests!
See the [todo list](https://github.com/duartegroup/autodE/projects/1) for features on the horizon.
Bugs and feature requests should be raised on the [issue page](https://github.com/duartegroup/autodE/issues).
Expand Down
2 changes: 1 addition & 1 deletion autode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
- Merge when tests pass
"""

__version__ = '1.2.2'
__version__ = '1.2.3'


__all__ = [
Expand Down
24 changes: 17 additions & 7 deletions autode/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def __init__(self,
atomic_symbol: str,
x: float = 0.0,
y: float = 0.0,
z: float = 0.0):
z: float = 0.0,
atom_class: Optional[int] = None):
"""
Atom class. Centered at the origin by default. Can be initialised from
positional or keyword arguments:
Expand All @@ -32,17 +33,23 @@ def __init__(self,
-----------------------------------------------------------------------
Arguments:
atomic_symbol (str): Symbol of an element e.g. 'C' for carbon
atomic_symbol: Symbol of an element e.g. 'C' for carbon
Keyword Arguments:
x (float): x coordinate in 3D space (Å)
y (float): y coordinate in 3D space (Å)
z (float): z coordinate in 3D space (Å)
x: x coordinate in 3D space (Å)
y: y coordinate in 3D space (Å)
z: z coordinate in 3D space (Å)
atom_class: Fictitious additional labels to distinguish otherwise
identical atoms. Useful in finding bond isomorphisms
over identity reactions
"""
assert atomic_symbol in elements

self.label = atomic_symbol
self._coord = Coordinate(float(x), float(y), float(z))
self.atom_class = atom_class

def __repr__(self):
"""
Expand Down Expand Up @@ -471,6 +478,9 @@ def rotate(self,

return None

def copy(self) -> 'Atom':
return deepcopy(self)

# --- Method aliases ---
coordinate = coord

Expand Down Expand Up @@ -733,7 +743,7 @@ class AtomCollection:
def __init__(self,
atoms: Union[List[Atom], Atoms, None] = None):
"""
Collection of atoms, used as a a base class for a species, complex
Collection of atoms, used as a base class for a species, complex
or transition state.
-----------------------------------------------------------------------
Expand Down
16 changes: 10 additions & 6 deletions autode/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def is_identical():
if not os.path.exists(register_name):
logger.info('No calculations have been performed here yet')
append_register()
return
return None

# Populate a register of calculation names and their unique identifiers
register = {}
Expand All @@ -189,13 +189,13 @@ def is_identical():

if is_identical():
logger.info('Calculation has already been run')
return
return None

# If this calculation doesn't yet appear in the register add it
if not exists():
logger.info('This calculation has not yet been run')
append_register()
return
return None

# If we're here then this calculation - with these input - has not yet
# been run. Therefore, add an integer to the calculation name until
Expand All @@ -209,7 +209,7 @@ def is_identical():
logger.info(f'New calculation name is: {self.name}')

if is_identical():
return
return None

if not exists():
append_register()
Expand Down Expand Up @@ -339,6 +339,10 @@ def get_final_atoms(self) -> Atoms:
raise ex.AtomsNotFound(f'Failed to get atoms from '
f'{self.output.filename}')

# Atom classes are persistent when calculations are performed
for old_atom, new_atom in zip(self.molecule.atoms, atoms):
new_atom.atom_class = old_atom.atom_class

return atoms

@_requires_set_output_filename
Expand Down Expand Up @@ -453,7 +457,7 @@ def clean_up(self,

if Config.keep_input_files and not force:
logger.info('Keeping input files')
return
return None

filenames = self.input.filenames
if everything:
Expand Down Expand Up @@ -500,7 +504,7 @@ def generate_input(self) -> None:
if not hasattr(keyword, self.method.name):
err_str = (f'Keyword: {keyword} is not supported set '
f'{repr(keyword)}.{self.method.name} as a string')
raise ex.UnsuppportedCalculationInput(err_str)
raise ex.UnsupportedCalculationInput(err_str)

self.method.generate_input(self, self.molecule)

Expand Down
78 changes: 75 additions & 3 deletions autode/conformers/conformer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from typing import Optional

from autode.atoms import Atoms
from autode.values import Coordinates
from autode.exceptions import AtomsNotFound
from autode.log import logger
from autode.species.species import Species
Expand All @@ -22,16 +25,19 @@ def __init__(self,
See Also:
(autode.species.species.Species):
"""

super().__init__(name, atoms, charge, mult, solvent_name=solvent_name)
self._parent_atoms = None
self._coordinates = None

if species is not None:
self._parent_atoms = species.atoms
self._coordinates = species.coordinates.copy()
self.charge = species.charge # Require identical charge/mult/solv
self.mult = species.mult
self.solvent = species.solvent

if atoms is None:
self.atoms = species.atoms.copy()
if atoms is not None: # Specified atoms overrides species
self.atoms = Atoms(atoms)

self.constraints.update(distance=dist_consts)

Expand Down Expand Up @@ -94,3 +100,69 @@ def optimise(self,
self.atoms = None

return None

@property
def coordinates(self) -> Optional[Coordinates]:
"""Coordinates of this conformer"""
return self._coordinates

@coordinates.setter
def coordinates(self, value: 'numpy.ndarray'):
"""Set the coordinates of this conformer"""
if self._parent_atoms is None:
raise ValueError('Conformer has no parent atoms. Setting the '
'coordinates will leave the atoms undefined')

self._coordinates = Coordinates(value)

@property
def atoms(self) -> Optional[Atoms]:
"""
Atoms of this conformer are built from the parent atoms and the
coordinates that are unique to this conformer.
"""

if self._parent_atoms is None or self._coordinates is None:
return None

atoms = Atoms()
for parent_atom, coord in zip(self._parent_atoms, self._coordinates):
atom = parent_atom.copy()
atom.coord = coord

atoms.append(atom)

return atoms

@atoms.setter
def atoms(self,
value: Optional[Atoms]):
"""
Set the atoms of this conformer.
If None then set the corresponding coordinates of this conformer to
None (such that self.atoms is None). If this conformer has coordinates
then set those from the individual atomic coordinates otherwise
set the coordinates as a batch
"""

if value is None: # Clear the coordinates
self._coordinates = None
return None

if self._parent_atoms is None:
self._parent_atoms = value

if self._coordinates is None:
self._coordinates = value.coordinates
return

for i, atom in enumerate(value):

parent_atom = self._parent_atoms[i]
if atom.label != parent_atom.label:
raise ValueError('Cannot alter the atomic symbols of a '
'conformer. Parent molecule was different: '
f'{atom.label} != {parent_atom.label}')

self._coordinates[i] = atom.coord.copy()
8 changes: 4 additions & 4 deletions autode/conformers/conformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def prune_on_rmsd(self,
if len(self) < 2:
logger.info(f'Only have {len(self)} conformers. No need to prune '
f'on RMSD')
return
return None

rmsd_tol = Config.rmsd_threshold if rmsd_tol is None else rmsd_tol

Expand Down Expand Up @@ -183,7 +183,7 @@ def prune_on_rmsd(self,
return None

def prune_diff_graph(self,
graph: 'networkx.Graph'
graph: 'autode.mol_graphs.MolecularGraph'
) -> None:
"""
Remove conformers with a different molecular graph to a defined
Expand All @@ -193,7 +193,7 @@ def prune_diff_graph(self,
-----------------------------------------------------------------------
Arguments:
graph (networkx.Graph): Reference graph
graph: Reference graph
"""
n_prev_confs = len(self)

Expand Down Expand Up @@ -225,7 +225,7 @@ def _parallel_calc(self, calc_type, method, keywords):
# TODO: Test efficiency + improve with dynamic load balancing
if len(self) == 0:
logger.error(f'Cannot run {calc_type} over 0 conformers')
return
return None

n_cores_pp = max(Config.n_cores // len(self), 1)

Expand Down
Loading

0 comments on commit d59fab9

Please sign in to comment.