-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from ZimmermanGroup:joshkamm/issue59
added basic mecp test
- Loading branch information
Showing
4 changed files
with
136 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.0.0+669.g640a1cf.dirty" | ||
__version__ = "1.0.0+681.g3b920bb.dirty" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import pytest | ||
|
||
from pyGSM.coordinate_systems.delocalized_coordinates import ( | ||
DelocalizedInternalCoordinates, | ||
) | ||
from pyGSM.coordinate_systems.primitive_internals import PrimitiveInternalCoordinates | ||
from pyGSM.coordinate_systems.topology import Topology | ||
from pyGSM.level_of_theories.xtb_lot import xTB_lot | ||
from pyGSM.molecule.molecule import Molecule | ||
from pyGSM.optimizers import eigenvector_follow | ||
from pyGSM.potential_energy_surfaces.penalty_pes import Penalty_PES | ||
from pyGSM.potential_energy_surfaces.pes import PES | ||
from pyGSM.utilities import elements, manage_xyz, nifty | ||
|
||
|
||
def test_basic_penalty_opt(): | ||
geom = manage_xyz.read_xyzs('pyGSM/data/diels_alder.xyz')[0] | ||
|
||
coupling_states = [] | ||
|
||
lot1 = xTB_lot.from_options( | ||
ID=0, | ||
states=[(1, 0)], | ||
gradient_states=[0], | ||
coupling_states=coupling_states, | ||
geom=geom, | ||
) | ||
|
||
lot2 = xTB_lot.from_options( | ||
ID=1, | ||
states=[(1, 0)], | ||
gradient_states=[0], | ||
coupling_states=coupling_states, | ||
geom=geom, | ||
) | ||
|
||
pes1 = PES.from_options( | ||
lot=lot1, | ||
multiplicity=1, | ||
ad_idx=0, | ||
) | ||
|
||
pes2 = PES.from_options( | ||
lot=lot2, | ||
multiplicity=1, | ||
ad_idx=0, | ||
) | ||
|
||
pes = Penalty_PES(PES1=pes1, PES2=pes2, lot=lot1) | ||
|
||
nifty.printcool('Building the topology') | ||
atom_symbols = manage_xyz.get_atoms(geom) | ||
ELEMENT_TABLE = elements.ElementData() | ||
atoms = [ELEMENT_TABLE.from_symbol(atom) for atom in atom_symbols] | ||
xyz1 = manage_xyz.xyz_to_np(geom) | ||
top1 = Topology.build_topology( | ||
xyz1, | ||
atoms, | ||
bondlistfile=None, | ||
) | ||
|
||
nifty.printcool('Building Primitive Internal Coordinates') | ||
connect = False | ||
addtr = True | ||
addcart = False | ||
p1 = PrimitiveInternalCoordinates.from_options( | ||
xyz=xyz1, | ||
atoms=atoms, | ||
connect=connect, | ||
addtr=addtr, | ||
addcart=addcart, | ||
topology=top1, | ||
) | ||
|
||
nifty.printcool('Building Delocalized Internal Coordinates') | ||
coord_obj1 = DelocalizedInternalCoordinates.from_options( | ||
xyz=xyz1, | ||
atoms=atoms, | ||
addtr=addtr, | ||
addcart=addcart, | ||
connect=connect, | ||
primitives=p1, | ||
) | ||
|
||
nifty.printcool('Building the molecule') | ||
|
||
Form_Hessian = True | ||
initial = Molecule.from_options( | ||
geom=geom, | ||
PES=pes, | ||
coord_obj=coord_obj1, | ||
Form_Hessian=Form_Hessian, | ||
) | ||
|
||
optimizer = eigenvector_follow.from_options( | ||
Linesearch='backtrack', # a step size algorithm | ||
OPTTHRESH=0.0005, # The gradrms threshold, this is generally easy to reach for large systems | ||
DMAX=0.01, # The initial max step size, will be adjusted if optimizer is doing well. Max is 0.5 | ||
conv_Ediff=0.1, # convergence of difference energy | ||
conv_dE=0.1, # convergence of energy difference between optimization steps | ||
conv_gmax=0.005, # convergence of max gradient | ||
opt_cross=True, # use difference energy criteria to determine if you are at crossing | ||
) | ||
|
||
print(' MECP optimization') | ||
geoms, energies = optimizer.optimize( | ||
molecule=initial, | ||
refE=initial.energy, | ||
opt_steps=150, # The max number of optimization steps, use a small number until you have your final sigma | ||
verbose=True, | ||
opt_type='UNCONSTRAINED', | ||
xyzframerate=1, | ||
) | ||
|
||
print(f'{energies = }') | ||
assert energies[-1] == pytest.approx(-1.1495296961093118) | ||
print('Finished!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters