From c77b4e4daa7f997f0975372541cd3eb172b759fb Mon Sep 17 00:00:00 2001 From: joshkamm Date: Fri, 26 Apr 2024 17:41:54 -0400 Subject: [PATCH 1/6] #59 added basic mecp test the test is just a reduntant minimization because both states are the same but it at least runs through the penalty pes class added typing-extensions to pyproject.toml because it wasn't being automatically installed even though xtb needs it --- pyGSM/_version.py | 2 +- pyGSM/tests/test_basic_mecp.py | 120 +++++++++++++++++++++++++++++++++ pyproject.toml | 4 ++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 pyGSM/tests/test_basic_mecp.py diff --git a/pyGSM/_version.py b/pyGSM/_version.py index de0d614..dbda468 100644 --- a/pyGSM/_version.py +++ b/pyGSM/_version.py @@ -1 +1 @@ -__version__ = "1.0.0+669.g640a1cf.dirty" +__version__ = "1.0.0+681.g3b920bb.dirty" diff --git a/pyGSM/tests/test_basic_mecp.py b/pyGSM/tests/test_basic_mecp.py new file mode 100644 index 0000000..7d6a3cc --- /dev/null +++ b/pyGSM/tests/test_basic_mecp.py @@ -0,0 +1,120 @@ +from openbabel import pybel as pb +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!') + + # print('Final energy is {:5.4f}'.format(initial.energy)) diff --git a/pyproject.toml b/pyproject.toml index 6fe28c4..7bb378f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ dependencies = [ "xtb", "sphinx", "sphinx_rtd_theme", + "typing-extensions", ] # Update the urls once the hosting is set up. @@ -92,3 +93,6 @@ default-tag = "1.0.0" [tool.versioningit.write] file = "pyGSM/_version.py" + +[tool.ruff.format] +quote-style = "single" From dba0b3670755c8a451376975634184a54d7d5386 Mon Sep 17 00:00:00 2001 From: joshkamm Date: Fri, 26 Apr 2024 17:46:23 -0400 Subject: [PATCH 2/6] #59 remove open babel import in basic mecp test --- pyGSM/tests/test_basic_mecp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyGSM/tests/test_basic_mecp.py b/pyGSM/tests/test_basic_mecp.py index 7d6a3cc..b7836aa 100644 --- a/pyGSM/tests/test_basic_mecp.py +++ b/pyGSM/tests/test_basic_mecp.py @@ -1,4 +1,3 @@ -from openbabel import pybel as pb import pytest from pyGSM.coordinate_systems.delocalized_coordinates import ( From b75b93520b4409bc7b569ddeea5344d43b0ce755 Mon Sep 17 00:00:00 2001 From: joshkamm Date: Fri, 26 Apr 2024 17:52:54 -0400 Subject: [PATCH 3/6] #59 update CI yaml file --- .github/workflows/CI.yaml | 57 ++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index a7d5c74..3563c58 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -24,30 +24,45 @@ jobs: python-version: [3.8, 3.9, "3.10"] steps: - - uses: actions/checkout@v3 - - - name: Additional info about the build - shell: bash + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + 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: | - uname -a - df -h - ulimit -a + uv pip install --system pytest + uv pip install --system -e . - # More info on options: https://github.com/marketplace/actions/provision-with-micromamba - - uses: mamba-org/provision-with-micromamba@main - with: - environment-file: devtools/conda-envs/test_env.yaml - environment-name: test - channels: conda-forge,defaults - extra-specs: | - python=${{ matrix.python-version }} + # - uses: actions/checkout@v3 - - name: Install package - # conda setup requires this special shell - shell: bash -l {0} - run: | - python -m pip install . --no-deps - micromamba list + # - 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 + # 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} + # run: | + # python -m pip install . --no-deps + # micromamba list - name: Run tests # conda setup requires this special shell From 01afe7f952bab77a39bcc697e6b34be72f4fec79 Mon Sep 17 00:00:00 2001 From: joshkamm Date: Fri, 26 Apr 2024 17:56:02 -0400 Subject: [PATCH 4/6] #59 updating CI yaml file --- .github/workflows/CI.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 3563c58..1a6a841 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -20,7 +20,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macOS-latest, ubuntu-latest, windows-latest] + # os: [macOS-latest, ubuntu-latest, windows-latest] + os: [ubuntu-latest] python-version: [3.8, 3.9, "3.10"] steps: From 2acf761d6b368da833092c6d3a5af29552a26259 Mon Sep 17 00:00:00 2001 From: joshkamm Date: Fri, 26 Apr 2024 18:01:05 -0400 Subject: [PATCH 5/6] #59 update CI yaml file --- .github/workflows/CI.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 1a6a841..a459120 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -72,7 +72,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 From 4cbabe0c31cdd5534aa866ddc980751c58846ad5 Mon Sep 17 00:00:00 2001 From: joshkamm Date: Fri, 26 Apr 2024 18:10:05 -0400 Subject: [PATCH 6/6] #59 cleaning up comments from files --- .github/workflows/CI.yaml | 26 -------------------------- pyGSM/tests/test_basic_mecp.py | 2 -- 2 files changed, 28 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index a459120..e7e3d12 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -20,7 +20,6 @@ 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"] @@ -40,31 +39,6 @@ jobs: uv pip install --system pytest uv pip install --system -e . - # - 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 - # 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} - # run: | - # python -m pip install . --no-deps - # micromamba list - - name: Run tests # conda setup requires this special shell shell: bash -l {0} diff --git a/pyGSM/tests/test_basic_mecp.py b/pyGSM/tests/test_basic_mecp.py index b7836aa..076f912 100644 --- a/pyGSM/tests/test_basic_mecp.py +++ b/pyGSM/tests/test_basic_mecp.py @@ -115,5 +115,3 @@ def test_basic_penalty_opt(): print(f'{energies = }') assert energies[-1] == pytest.approx(-1.1495296961093118) print('Finished!') - - # print('Final energy is {:5.4f}'.format(initial.energy))