Skip to content

Commit

Permalink
Merge pull request #60 from ZimmermanGroup:joshkamm/issue59
Browse files Browse the repository at this point in the history
added basic mecp test
  • Loading branch information
joshkamm authored Apr 26, 2024
2 parents 3b920bb + 4cbabe0 commit 295dc46
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 25 deletions.
38 changes: 14 additions & 24 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,24 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-latest, ubuntu-latest, windows-latest]
os: [ubuntu-latest]
python-version: [3.8, 3.9, "3.10"]

steps:
- uses: actions/checkout@v3

- name: Additional info about the build
shell: bash
run: |
uname -a
df -h
ulimit -a
# More info on options: https://github.com/marketplace/actions/provision-with-micromamba
- uses: mamba-org/provision-with-micromamba@main
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
environment-file: devtools/conda-envs/test_env.yaml
environment-name: test
channels: conda-forge,defaults
extra-specs: |
python=${{ matrix.python-version }}
- name: Install package
# conda setup requires this special shell
shell: bash -l {0}
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: |
python -m pip install . --no-deps
micromamba list
uv pip install --system pytest
uv pip install --system -e .
- name: Run tests
# conda setup requires this special shell
Expand All @@ -56,7 +46,7 @@ jobs:
pytest -v --cov=pyGSM --cov-report=xml --color=yes pyGSM/tests/
- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
Expand Down
2 changes: 1 addition & 1 deletion pyGSM/_version.py
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"
117 changes: 117 additions & 0 deletions pyGSM/tests/test_basic_mecp.py
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!')
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies = [
"xtb",
"sphinx",
"sphinx_rtd_theme",
"typing-extensions",
]

# Update the urls once the hosting is set up.
Expand Down Expand Up @@ -92,3 +93,6 @@ default-tag = "1.0.0"

[tool.versioningit.write]
file = "pyGSM/_version.py"

[tool.ruff.format]
quote-style = "single"

0 comments on commit 295dc46

Please sign in to comment.