Skip to content

Commit

Permalink
Merge pull request #189 from andrewtarzia/optwriter_sequence
Browse files Browse the repository at this point in the history
Adds a new sequence optimiser that writes to file each step to avoid rerun, fixes the docs and makes all code examples tests, which are passing now. Had to set a numpy version requirement because the order of installation could be an issue
  • Loading branch information
andrewtarzia authored Nov 15, 2024
2 parents e08de00 + cad25d6 commit c39a56a
Show file tree
Hide file tree
Showing 35 changed files with 848 additions and 89 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Build environment
run: |
conda activate pytest
conda install -c conda-forge openff-toolkit openmm openmmtools dgl
conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install -e '.[dev]'
Expand All @@ -79,7 +79,7 @@ jobs:
- name: Build environment
run: |
conda activate pytest
conda install -c conda-forge openff-toolkit openmm openmmtools dgl
conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4
conda install -c conda-forge mdanalysis openbabel
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
Expand All @@ -104,7 +104,8 @@ jobs:
- name: Build environment
run: |
conda activate pytest
conda install -c conda-forge openff-toolkit openmm openmmtools dgl
conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4
conda install -c conda-forge mdanalysis openbabel
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install -e '.[dev]'
Expand Down
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Some optional dependencies are only available through conda:
.. code-block:: bash
# for OpenMM and espaloma charge
mamba install openff-toolkit openmm openmmtools dgl
# note the temporary issue with rdkit versions and conda will overwrite pip
# installed software
mamba install openff-toolkit openmm openmmtools dgl rdkit==2024.3.4
# for xtb
mamba install xtb
# for openbabel
Expand Down
46 changes: 27 additions & 19 deletions docs/source/cage_analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,21 @@ This example structure is not great, but it does the job here. Imagine
you would do a better optimisation with one of our
`Optimizer <optimizers.html>`_ classes!

.. code-block:: python
.. testsetup:: analysing-cage

import pathlib
import os

path = pathlib.Path('cage_output')
os.makedirs(path, exist_ok=True)


.. testcode:: analysing-cage

import stk
import stko
import numpy as np
from collections import defaultdict

pd = stk.BuildingBlock(
smiles="[Pd+2]",
Expand Down Expand Up @@ -141,13 +152,12 @@ functional group has three atoms, centered on a binder, which we can then
pass to the ``stko.molecule_analysis.DitopicThreeSiteAnalyser`` for
automatic analyses.

.. code-block:: python
.. testcode:: analysing-cage

ligands = stko.molecule_analysis.DecomposeMOC().decompose(
molecule=apdcage,
metal_atom_nos=(46,),
)
print(f"there are {len(ligands)} ligands")

tsa = stko.molecule_analysis.DitopicThreeSiteAnalyser()
ligand_dict = defaultdict(list)
Expand Down Expand Up @@ -197,7 +207,7 @@ We can get the centroid and atom ids of distinct building blocks.
This simply extracts the parts of building blocks still present in the
molecule.

.. code-block:: python
.. testcode:: analysing-cage


analyser = stko.molecule_analysis.ConstructedAnalyser()
Expand All @@ -207,37 +217,29 @@ molecule.

We can get measures of pore size and cage geometry.

.. code-block:: python
.. testcode:: analysing-cage

analyser = stko.molecule_analysis.GeometryAnalyser()
print(
f"approximate pore size: {analyser.get_min_centroid_distance(apdcage)}"
)
print(f"avg cage size: {analyser.get_avg_centroid_distance(apdcage)}")
pore_size = analyser.get_min_centroid_distance(apdcage)
avg_cage_size = analyser.get_avg_centroid_distance(apdcage)
m_distances = list(
analyser.get_metal_distances(
apdcage,
metal_atom_nos=(46,),
).values()
)
print(f"avg. metal distance: {np.mean(m_distances)}")
avg_m_distances = np.mean(m_distances)
m_angles = list(
analyser.get_metal_centroid_metal_angle(
apdcage,
metal_atom_nos=(46,),
).values()
)
print(f"avg. metal-centroid-angles: {np.mean(m_angles)}")
avg_m_angles = np.mean(m_angles)

# And some geometrical measures.
print(
f"avg. N-Pd bond length:"
f' {np.mean(analyser.calculate_bonds(apdcage)[("N", "Pd")])}'
)
print(
f"N-Pd-N angles: "
f'{analyser.calculate_angles(apdcage)[("N", "Pd", "N")]}'
)
avg_n_pd_bond_length = np.mean(analyser.calculate_bonds(apdcage)[("N", "Pd")])
n_pd_n_angles = analyser.calculate_angles(apdcage)[("N", "Pd", "N")]

Giving:

Expand All @@ -249,3 +251,9 @@ Giving:
avg. metal-centroid-angles: 107.491677523429
avg. N-Pd bond length: 2.0559406288465105
N-Pd-N angles: [175.92946759351747, 89.4607655701432, 92.55953467090808, ...]
.. testcleanup:: analysing-cage

import shutil

shutil.rmtree('cage_output')
178 changes: 176 additions & 2 deletions docs/source/cage_optimisation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,182 @@ to get the structure below in a few minutes!
smiles="C1=C(C=C(C=C1C=O)C=O)C=O",
functional_groups=[stk.AldehydeFactory()],
)
cage = stk.BuildingBlock.init_from_file(
'source/_static/openmm_opt_file.mol'
cage = stk.ConstructedMolecule(
topology_graph=stk.cage.FourPlusSix((bb1, bb2)),
)
cage = cage.with_position_matrix(
np.array(
(
(-1.9792, -2.3384, 5.2933),
(-3.2185, -2.0128, 4.7072),
(-3.3418, -0.8081, 3.9884),
(-2.2459, 0.0633, 3.8438),
(-1.0129, -0.2787, 4.4340),
(-0.8691, -1.4797, 5.1587),
(0.4539, -1.8374, 5.7277),
(-2.4066, 1.2933, 3.0336),
(-4.3549, -2.9589, 4.8174),
(-1.8487, -3.2699, 5.8281),
(-4.2896, -0.5827, 3.5176),
(-0.1724, 0.3871, 4.2901),
(1.2798, -1.1664, 5.5382),
(-3.3696, 1.4629, 2.5733),
(-4.1898, -3.8917, 5.3382),
(-4.7803, -5.2041, -0.1516),
(-4.3247, -6.0542, 0.8753),
(-3.3559, -7.0307, 0.5802),
(-2.8384, -7.1630, -0.7222),
(-3.3237, -6.3243, -1.7450),
(-4.2922, -5.3406, -1.4672),
(-4.7621, -4.4130, -2.5213),
(-1.7453, -8.1184, -1.0084),
(-4.8125, -5.9199, 2.2663),
(-5.5032, -4.4377, 0.0956),
(-2.9651, -7.6718, 1.3590),
(-2.9383, -6.3968, -2.7529),
(-5.1288, -3.4502, -2.1965),
(-1.1578, -7.9386, -1.8973),
(-4.3149, -6.4955, 3.0355),
(2.3470, -5.6245, 2.4744),
(3.0253, -4.3910, 2.4097),
(3.4773, -3.9184, 1.1616),
(3.2342, -4.6532, -0.0146),
(2.5581, -5.8863, 0.0689),
(2.1190, -6.3844, 1.3104),
(1.3921, -7.6722, 1.4108),
(3.6201, -4.1242, -1.3411),
(3.2214, -3.5604, 3.6207),
(1.9818, -5.9636, 3.4353),
(3.9801, -2.9641, 1.0784),
(2.3476, -6.4622, -0.8217),
(0.8728, -7.8922, 2.3343),
(3.0634, -4.4889, -2.1917),
(3.5944, -2.5529, 3.4935),
(0.0003, 0.1776, -1.6595),
(-1.4006, 0.2907, -1.7411),
(-2.1049, -0.5319, -2.6414),
(-1.4225, -1.4575, -3.4556),
(-0.0176, -1.5471, -3.3710),
(0.7007, -0.7336, -2.4734),
(2.1741, -0.8221, -2.3473),
(-2.1595, -2.3694, -4.3603),
(-2.1436, 1.2339, -0.8736),
(0.5263, 0.7923, -0.9400),
(-3.1838, -0.4868, -2.7014),
(0.5309, -2.2582, -3.9736),
(2.6371, -0.3127, -1.5126),
(-1.6213, -3.2046, -4.7884),
(-3.2228, 1.1631, -0.8483),
(-8.7475, -5.4098, 3.2440),
(-9.0659, -3.9533, 3.6377),
(-7.8037, -3.0695, 3.5465),
(-6.6610, -3.6323, 4.4095),
(-6.3139, -5.0978, 3.9792),
(-7.5791, -5.9787, 4.0854),
(-5.8477, -5.1698, 2.5758),
(-5.5362, -2.6767, 4.3083),
(-8.4781, -5.4466, 2.1851),
(-9.6340, -6.0334, 3.3680),
(-9.4577, -3.9245, 4.6560),
(-9.8412, -3.5549, 2.9807),
(-8.0337, -2.0536, 3.8688),
(-7.4661, -3.0074, 2.5101),
(-6.9999, -3.6461, 5.4468),
(-5.5532, -5.4945, 4.6537),
(-7.3453, -6.9888, 3.7459),
(-7.8813, -6.0535, 5.1302),
(4.3501, -5.0254, 7.2779),
(3.1457, -5.1703, 8.2306),
(1.8378, -4.7139, 7.5481),
(1.9504, -3.2750, 7.0131),
(3.1487, -3.1507, 6.0102),
(4.4541, -3.5888, 6.7112),
(2.9636, -4.0200, 4.8266),
(0.6242, -2.9236, 6.4531),
(4.2421, -5.7299, 6.4492),
(5.2718, -5.2881, 7.7993),
(3.3146, -4.5744, 9.1291),
(3.0491, -6.2107, 8.5468),
(1.0084, -4.7732, 8.2535),
(1.5972, -5.3812, 6.7182),
(2.1399, -2.6169, 7.8624),
(3.2503, -2.1082, 5.7047),
(5.2801, -3.5366, 6.0004),
(4.6810, -2.8918, 7.5183),
(-1.0278, 5.1099, -0.3060),
(-0.3333, 5.3337, 1.0526),
(-0.2367, 4.0142, 1.8498),
(-1.6218, 3.3715, 2.0394),
(-2.3076, 3.1120, 0.6526),
(-2.4117, 4.4416, -0.1254),
(-1.5287, 2.1705, -0.1833),
(-1.4305, 2.1619, 2.8727),
(-0.3987, 4.4713, -0.9318),
(-1.1389, 6.0602, -0.8304),
(-0.8928, 6.0690, 1.6334),
(0.6670, 5.7401, 0.8924),
(0.2126, 4.1982, 2.8262),
(0.4129, 3.3090, 1.3278),
(-2.2390, 4.0725, 2.6039),
(-3.3151, 2.7281, 0.8187),
(-2.8578, 4.2533, -1.1031),
(-3.0784, 5.1198, 0.4077),
(2.3815, -11.0436, -0.9318),
(1.2844, -11.1927, -2.0094),
(0.2185, -10.0819, -1.8754),
(-0.3832, -10.0826, -0.4473),
(0.7226, -9.8624, 0.6209),
(1.7792, -10.9799, 0.4942),
(1.4225, -8.5662, 0.4443),
(-1.5084, -9.1419, -0.2118),
(2.9494, -10.1287, -1.1196),
(3.0863, -11.8738, -0.9990),
(0.8065, -12.1694, -1.9127),
(1.7363, -11.1510, -3.0023),
(-0.5726, -10.2374, -2.6099),
(0.6820, -9.1150, -2.0791),
(-0.7920, -11.0790, -0.2724),
(0.2645, -9.9205, 1.6110),
(2.5743, -10.8053, 1.2204),
(1.3215, -11.9378, 0.7429),
(-5.7675, -1.3419, -6.3528),
(-6.9145, -2.0492, -5.5981),
(-6.3712, -2.8433, -4.3903),
(-5.2902, -3.8534, -4.8500),
(-4.1141, -3.1344, -5.5638),
(-4.6593, -2.3401, -6.7712),
(-3.4263, -2.1784, -4.6643),
(-4.7907, -4.7707, -3.7910),
(-5.3308, -0.5745, -5.7086),
(-6.1603, -0.8326, -7.2342),
(-7.4381, -2.7264, -6.2754),
(-7.6407, -1.3096, -5.2559),
(-7.1839, -3.3766, -3.8957),
(-5.9431, -2.1431, -3.6717),
(-5.7571, -4.4978, -5.5969),
(-3.4162, -3.8928, -5.9258),
(-3.8390, -1.8005, -7.2469),
(-5.0564, -3.0368, -7.5099),
(4.7797, -1.7686, -5.5998),
(5.3604, -3.1692, -5.3070),
(4.7690, -3.7441, -4.0020),
(5.0246, -2.7739, -2.8224),
(4.4044, -1.3765, -3.0936),
(4.9868, -0.8052, -4.4052),
(2.9293, -1.4185, -3.2470),
(4.6293, -3.2878, -1.4857),
(3.7098, -1.8569, -5.8039),
(5.2419, -1.3522, -6.4964),
(6.4470, -3.1069, -5.2207),
(5.1393, -3.8409, -6.1385),
(5.2166, -4.7142, -3.7828),
(3.6966, -3.8914, -4.1361),
(6.1042, -2.6245, -2.7671),
(4.6823, -0.7125, -2.2719),
(4.5102, 0.1523, -4.6210),
(6.0517, -0.6121, -4.2723),
)
)
)

moldoc_display_molecule = molecule.Molecule(
Expand Down
4 changes: 3 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Some optional dependencies are only available through conda:
.. code-block:: bash
# for OpenMM and espaloma charge
mamba install openff-toolkit openmm openmmtools dgl
# note the temporary issue with rdkit versions and conda will overwrite pip
# installed software
mamba install openff-toolkit openmm openmmtools dgl rdkit==2024.3.4
# for xtb
mamba install xtb
# for openbabel
Expand Down
4 changes: 3 additions & 1 deletion docs/source/optimizers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Optimizers
.. toctree::
:maxdepth: 1

NullOptimizer <_autosummary/stko.NullOptimizer>
OptimizerSequence <_autosummary/stko.OptimizerSequence>
OptWriterSequence <_autosummary/stko.OptWriterSequence>
TryCatchOptimizer <_autosummary/stko.TryCatchOptimizer>

Aligner <_autosummary/stko.Aligner>
Expand All @@ -21,7 +23,6 @@ Optimizers
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 All @@ -31,3 +32,4 @@ Optimizers

GulpUFFMDOptimizer <_autosummary/stko.GulpUFFMDOptimizer>
MacroModelMD <_autosummary/stko.MacroModelMD>
OpenMMMD <_autosummary/stko.OpenMMMD>
Loading

0 comments on commit c39a56a

Please sign in to comment.