Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lukas/more optimizers #183

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b792271
wip
lukasturcani Jul 9, 2024
cae5aca
wip
lukasturcani Jul 9, 2024
b3b8421
wip
lukasturcani Jul 19, 2024
99a5162
wip
lukasturcani Jul 24, 2024
436801f
wip
lukasturcani Jul 24, 2024
38fce29
wip
lukasturcani Jul 24, 2024
820999f
wip
lukasturcani Jul 24, 2024
74fe99f
Merge branch 'main' of github.com:andrewtarzia/stko into lukas/more-o…
andrewtarzia Jul 24, 2024
c97f7c5
Add install instructions.
andrewtarzia Jul 30, 2024
0613b74
Add optimiser settings.
andrewtarzia Jul 30, 2024
54b76a8
Update output.
andrewtarzia Jul 30, 2024
b1091a5
Add restricted optimisation.
andrewtarzia Jul 30, 2024
ae892d6
Add restricted optimisation.
andrewtarzia Jul 30, 2024
d77f061
Finish example api.
andrewtarzia Jul 30, 2024
d082fe8
Add openmm energy calculator.
andrewtarzia Jul 30, 2024
9a762b3
Remove unnecessary gpu usage.
andrewtarzia Jul 30, 2024
95f547d
Add simulation setup.
andrewtarzia Jul 30, 2024
f957f4b
Add conformer optimisation.
andrewtarzia Jul 30, 2024
f1d0115
Add example output.
andrewtarzia Jul 30, 2024
feb1ed9
Add and use null optimiser.
andrewtarzia Jul 31, 2024
d795267
nice
lukasturcani Jul 31, 2024
e2d21e1
nice
lukasturcani Jul 31, 2024
1b44392
Merge branch 'master' into lukas/more-optimizers
lukasturcani Jul 31, 2024
fcd8968
wip
lukasturcani Jul 31, 2024
13ad414
wip
lukasturcani Aug 27, 2024
bb252fe
Fix
lukasturcani Aug 27, 2024
bcc9ef9
wip
lukasturcani Aug 27, 2024
ae6a1c6
working
lukasturcani Aug 27, 2024
82cb1bf
update env file
lukasturcani Aug 27, 2024
7427f3e
wip
lukasturcani Aug 27, 2024
0f3dfbd
fix stuff
lukasturcani Aug 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ jobs:
- run: "pip install -e '.[dev]'"
- run: ruff format --check .
pytest:
# https://ericmjl.github.io/blog/2021/12/30/better-conda-environments-on-github-actions/
runs-on: ubuntu-22.04
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v3
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniforge-variant: Mambaforge
channels: conda-forge,defaults
python-version: 3.11
activate-environment: pytest
use-mamba: true
- name: Build environment
run: |
conda activate pytest
conda install -c conda-forge openmm openmmtools
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install -e '.[dev]'
- run: pytest
doctest:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
Expand All @@ -45,4 +69,4 @@ jobs:
python-version: "3.11"
cache: "pip"
- run: "pip install -e '.[dev]'"
- run: pytest
- run: make -C docs doctest
16 changes: 6 additions & 10 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
version: 2

build:
os: "ubuntu-22.04"
tools:
python: "3.11"
os: "ubuntu-22.04"
tools:
python: "mambaforge-latest"

sphinx:
configuration: "docs/source/conf.py"
configuration: "docs/source/conf.py"

python:
install:
- method: "pip"
path: .
extra_requirements:
- "dev"
conda:
environment: "docs/environment.yml"
23 changes: 13 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ for ``stk``, which can be joined through https://discord.gg/zbCUzuxe2B.
Installation
============

To get ``stko``, you can install it with pip::
To get ``stko``, you can install it with pip:

$ pip install stko
.. code-block:: bash

You can also install xtb, which is an optional dependency::
pip install stko

$ conda install -c conda-forge xtb
Some optional dependencies are only available through conda:

You can also install openbabel, which is an optional dependency::
.. code-block:: bash

$ conda install -c conda-forge openbabel

You can also install MDAnalysis, which is an optional dependency::

$ conda install -c mdanalysis
# for OpenMM
mamba install openff-toolkit openmm openmmtools
# for xtb
mamba install xtb
# for openbabel
mamba install openbabel
# for mdanalysis
mamba install mdanalysis

Examples
========
Expand Down
15 changes: 15 additions & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
channels:
- conda-forge
- defaults
dependencies:
- openff-toolkit
- openmm
- openmmtools
- python=3.11
- pip
- pip:
- numpy
- rdkit
- stk
- networkx
- rmsd
1 change: 1 addition & 0 deletions docs/source/calculators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Calculators
MMFFEnergy <_autosummary/stko.MMFFEnergy>
UFFEnergy <_autosummary/stko.UFFEnergy>
OpenBabelEnergy <_autosummary/stko.OpenBabelEnergy>
OpenMMEnergy <_autosummary/stko.OpenMMEnergy>
XTBEnergy <_autosummary/stko.XTBEnergy>
OrcaEnergy <_autosummary/stko.OrcaEnergy>
RmsdCalculator <_autosummary/stko.RmsdCalculator>
Expand Down
5 changes: 5 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pandas": ("https://pandas.pydata.org/docs/", None),
"openff": (
"https://docs.openforcefield.org/projects/toolkit/en/stable/",
None,
),
"openmm": ("http://docs.openmm.org/latest/api-python/", None),
}

templates_path = ["_templates"]
Expand Down
25 changes: 21 additions & 4 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@ GitHub: https://github.com/JelfsMaterialsGroup/stko
Install
=======

:mod:`.stko` can be installed directly with pip::
:mod:`.stko` can be installed directly with pip:

$ pip install stko
.. code-block:: bash

pip install stko

Some optional dependencies are only available through conda:

.. code-block:: bash

# for OpenMM
mamba install openff-toolkit openmm openmmtools
# for xtb
mamba install xtb
# for openbabel
mamba install openbabel
# for mdanalysis
mamba install mdanalysis


Dependencies
Expand All @@ -42,14 +57,16 @@ on the desired functions used. These are:
* `GULP <http://gulp.curtin.edu.au/gulp/>`_
* `XTB <https://xtb-docs.readthedocs.io/en/latest/>`_
* `OpenBabel <https://github.com/openbabel/openbabel>`_
* `OpenMM <https://openmm.org/>`_
* `OpenFF <https://openforcefield.org/>`_


Overview
========

`stko <https://github.com/lukasturcani/stk>`_ is a Python library which
`stko <https://github.com/JelfsMaterialsGroup/stko>`_ is a Python library which
performs optimizations and calculations on complex molecules built using
`stk <https://github.com/JelfsMaterialsGroup/stko>`_. In the case of
`stk <https://github.com/lukasturcani/stk>`_. In the case of
optimizations, a clone of :class:`stk.Molecule` is returned. For
calculators, a ``Results`` class are used to calculate and extract
properties of an :class:`stk.Molecule`.
Expand Down
2 changes: 2 additions & 0 deletions docs/source/optimizers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Optimizers
MMFF <_autosummary/stko.MMFF>
MetalOptimizer <_autosummary/stko.MetalOptimizer>
OpenBabel <_autosummary/stko.OpenBabel>
OpenMMForceField <_autosummary/stko.OpenMMForceField>
OpenMMMD <_autosummary/stko.OpenMMMD>
GulpUFFOptimizer <_autosummary/stko.GulpUFFOptimizer>
MacroModelForceField <_autosummary/stko.MacroModelForceField>
XTB <_autosummary/stko.XTB>
Expand Down
1 change: 1 addition & 0 deletions examples/aligner_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
import stk

import stko


Expand Down
1 change: 1 addition & 0 deletions examples/basic_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

import stk

import stko


Expand Down
1 change: 1 addition & 0 deletions examples/cage_analysis_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import stk

import stko


Expand Down
1 change: 1 addition & 0 deletions examples/calculators_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import stk

import stko


Expand Down
1 change: 1 addition & 0 deletions examples/gulp_test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import stk

import stko


Expand Down
1 change: 1 addition & 0 deletions examples/mdanalysis_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ruff: noqa: T201
import numpy as np
import stk

import stko


Expand Down
1 change: 1 addition & 0 deletions examples/molecule_splitter_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import stk

import stko


Expand Down
1 change: 1 addition & 0 deletions examples/obabel_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
import stk

import stko


Expand Down
102 changes: 102 additions & 0 deletions examples/openmm_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# ruff: noqa: T201

from pathlib import Path

import openmm
import stk
from openff.toolkit import ForceField

import stko


def main() -> None:
"""Run the example."""
bb1 = stk.BuildingBlock("C1CCC(C(C1)N)N", [stk.PrimaryAminoFactory()])
bb2 = stk.BuildingBlock(
"C1=C(C=C(C=C1C=O)C=O)C=O", [stk.AldehydeFactory()]
)
output = Path("openmm_example_directory")
output.mkdir(exist_ok=True, parents=True)
cage = stk.ConstructedMolecule(stk.cage.FourPlusSix([bb1, bb2]))
cage.write(output / "unopt_cage.mol")
ff_optimizer = stko.OpenMMForceField(
# Load the openff-2.1.0 force field appropriate for
# vacuum calculations (without constraints)
force_field=ForceField("openff_unconstrained-2.1.0.offxml"),
partial_charges_method="mmff94",
max_iterations=10,
)
ff_cage = ff_optimizer.optimize(cage)
ff_cage.write(output / "ff_opt_cage.mol")
print(
"ff_opt_cage",
stko.OpenMMEnergy(
force_field=ForceField("openff_unconstrained-2.1.0.offxml"),
partial_charges_method="mmff94",
).get_energy(ff_cage),
)

ff_optimizer = stko.OpenMMForceField(
# Load the openff-2.1.0 force field appropriate for
# vacuum calculations (without constraints)
force_field=ForceField("openff_unconstrained-2.1.0.offxml"),
restricted=False,
partial_charges_method="mmff94",
)
ff_cage = ff_optimizer.optimize(cage)
ff_cage.write(output / "ffunrest_opt_cage.mol")
print(
"ffunrest_opt_cage",
stko.OpenMMEnergy(
force_field=ForceField("openff_unconstrained-2.1.0.offxml"),
partial_charges_method="mmff94",
).get_energy(ff_cage),
)

ff_optimizer = stko.OpenMMForceField(
# Load the openff-2.1.0 force field appropriate for
# vacuum calculations (without constraints)
force_field=ForceField("openff_unconstrained-2.1.0.offxml"),
restricted=True,
partial_charges_method="mmff94",
)
ff_cage = ff_optimizer.optimize(cage)
ff_cage.write(output / "ffrest_opt_cage.mol")
print(
"ffrest_opt_cage",
stko.OpenMMEnergy(
force_field=ForceField("openff_unconstrained-2.1.0.offxml"),
partial_charges_method="mmff94",
).get_energy(ff_cage),
)

temperature = 750 * openmm.unit.kelvin
friction = 10 / openmm.unit.picoseconds
time_step = 1 * openmm.unit.femtoseconds
integrator = openmm.LangevinIntegrator(temperature, friction, time_step)
integrator.setRandomNumberSeed(127)
md_optimizer = stko.OpenMMMD(
force_field=ForceField("openff_unconstrained-2.1.0.offxml"),
output_directory=output / "md_optimisation",
integrator=integrator,
random_seed=275,
partial_charges_method="mmff94",
reporting_freq=5,
trajectory_freq=5,
num_steps=10000,
num_conformers=50,
platform="CUDA",
)
md_cage = md_optimizer.optimize(cage)
md_cage.write(output / "md_opt_cage.mol")
print(
"md_opt_cage",
stko.OpenMMEnergy(
force_field=ForceField("openff_unconstrained-2.1.0.offxml"),
partial_charges_method="mmff94",
).get_energy(md_cage),
)


if __name__ == "__main__":
main()
Loading
Loading