Skip to content

Commit

Permalink
Updated other wrappers and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom committed Jul 10, 2020
1 parent b5bd840 commit 21040b0
Show file tree
Hide file tree
Showing 24 changed files with 2,327 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ tests/.autode_calculations
tests/data/complex_conf*.xyz

tests/data/*.com

tests/data/conformers/.autode_calculations

tests/data/orca/.autode_calculations

tests/data/xtb/.autode_calculations
18 changes: 12 additions & 6 deletions autode/smiles/smiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@


def calc_multiplicity(molecule, n_radical_electrons):
"""Calculate the spin multiplicity 2S + 1 where S is the number of unpaired electrons
"""Calculate the spin multiplicity 2S + 1 where S is the number of
unpaired electrons
Arguments:
molecule (autode.molecule.Molecule):
n_radical_electrons (int):
Expand All @@ -24,20 +26,23 @@ def calc_multiplicity(molecule, n_radical_electrons):
return 1

if molecule.mult == 1 and n_radical_electrons == 1:
# Cannot have multiplicity = 1 and 1 radical electrons – override default multiplicity
# Cannot have multiplicity = 1 and 1 radical electrons – override
# default multiplicity
return 2

if molecule.mult == 1 and n_radical_electrons > 1:
logger.warning('Diradicals by default singlets. Set mol.mult if it\'s any different')
logger.warning('Diradicals by default singlets. Set mol.mult if it\'s '
'any different')
return 1

return molecule.mult


def init_organic_smiles(molecule, smiles):
"""
Initialise a molecule from a SMILES string, set the charge, multiplicity (if it's not already specified) and the 3D
geometry using RDKit
Initialise a molecule from a SMILES string, set the charge, multiplicity (
if it's not already specified) and the 3D geometry using RDKit
Arguments:
molecule (autode.molecule.Molecule):
smiles (str): SMILES string
Expand Down Expand Up @@ -114,7 +119,8 @@ def init_smiles(molecule, smiles):

def check_bonds(molecule, bonds):
"""
Ensure the SMILES string and the 3D structure have the same bonds, but don't override
Ensure the SMILES string and the 3D structure have the same bonds,
but don't override
Arguments:
molecule (autode.molecule.Molecule):
Expand Down
11 changes: 8 additions & 3 deletions autode/wrappers/G09.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from copy import deepcopy
import numpy as np
from autode.constants import Constants
from autode.wrappers.base import ElectronicStructureMethod
from autode.utils import run_external
from autode.atoms import Atom
Expand Down Expand Up @@ -440,16 +441,20 @@ def get_gradients(self, calc):
gradients_section = False

if gradients_section and len(line.split()) == 5:
_, _, x, y, z = line.split()
_, _, fx, fy, fz = line.split()
try:
gradients.append([float(x), float(y), float(z)])
# Ha / a0
force = np.array([float(fx), float(fy), float(fz)])

grad = -force / Constants.a02ang
gradients.append(grad)
except ValueError:
pass
for line in gradients:
for i in range(3):
line[i] *= -1

return gradients
return np.array(gradients)

def __init__(self):
super().__init__(name='g09', path=Config.G09.path,
Expand Down
2 changes: 1 addition & 1 deletion autode/wrappers/MOPAC.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def get_gradients(self, calc):
_, _, _, _, _, _, value, _ = line.split()
gradients.append(value)
grad_array = np.asarray(gradients)
grad_array *= Constants.a02ang/Constants.ha2kcalmol
grad_array /= Constants.ha2kcalmol # From kcal mol-1 Å^-1 to Ha Å^-1
grad_array.reshape((calc.molecule.n_atoms, 3))

return grad_array.tolist()
Expand Down
6 changes: 4 additions & 2 deletions autode/wrappers/NWChem.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,11 @@ def get_gradients(self, calc):

if gradients_section and len(line.split()) == 8:
x, y, z = line.split()[5:]
gradients.append([float(x), float(y), float(z)])
gradients.append(np.array([float(x), float(y), float(z)]))

return gradients
# Convert from Ha a0^-1 to Ha A-1
gradients = [grad / Constants.a02ang for grad in gradients]
return np.array(gradients)

def __init__(self):
super().__init__('nwchem', path=Config.NWChem.path,
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/molecules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ Calculations

**autodE** provides wrappers around common electronic structure theory packages
(ORCA, XTB, NWChem, MOPAC, Gaussian09) so geometries may be optimised and
energies calculated.
energies calculated. Energies are in atomic Hartrees and gradients in
Ha / Å.

For example, to optimise the geometry at the XTB level and then perform a
single point energy evaluation with ORCA
Expand Down
Loading

0 comments on commit 21040b0

Please sign in to comment.