Skip to content

Commit

Permalink
Merge pull request #196 from andrewtarzia/main
Browse files Browse the repository at this point in the history
Implement unreacted graph and example.
  • Loading branch information
andrewtarzia authored Dec 18, 2024
2 parents 4e2e151 + 4eff369 commit a57cec0
Show file tree
Hide file tree
Showing 29 changed files with 1,314 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
cache: "pip"
- run: "pip install '.[dev]'"
- run: ruff check .

mypy:
runs-on: ubuntu-22.04
steps:
Expand All @@ -26,6 +27,7 @@ jobs:
cache: "pip"
- run: "pip install -e '.[dev]'"
- run: mypy src examples

ruff-format:
runs-on: ubuntu-22.04
steps:
Expand All @@ -36,6 +38,7 @@ jobs:
cache: "pip"
- 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
Expand All @@ -56,10 +59,12 @@ jobs:
run: |
conda activate pytest
conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 espaloma_charge
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]'
- run: pytest

example-tests:
# https://ericmjl.github.io/blog/2021/12/30/better-conda-environments-on-github-actions/
runs-on: ubuntu-22.04
Expand All @@ -86,6 +91,7 @@ jobs:
python -m pip install -e '.[dev]'
- name: Run script
run: python examples/testable_example.py

doctest:
runs-on: ubuntu-22.04
defaults:
Expand Down
3 changes: 3 additions & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ dependencies:
- pip
- rdkit==2024.3.4
- espaloma_charge
- mdanalysis
- openbabel

26 changes: 14 additions & 12 deletions docs/source/_templates/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

.. automodule:: {{ fullname }}

{% block modules %}
{% if modules %}
.. rubric:: Modules

.. autosummary::
:toctree:
:template: module.rst
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: Module attributes
Expand Down Expand Up @@ -53,16 +67,4 @@
{% endif %}
{% endblock %}

{% block modules %}
{% if modules %}
.. rubric:: Modules

.. autosummary::
:toctree:
:template: module.rst
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
18 changes: 18 additions & 0 deletions docs/source/cage_analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ you would do a better optimisation with one of our

import pathlib
import os
import numpy as np

path = pathlib.Path('cage_output')
os.makedirs(path, exist_ok=True)
Expand Down Expand Up @@ -186,6 +187,12 @@ automatic analyses.
sum(tsa.get_halfbite_angles(as_building_block))
)

.. testcode:: analysing-cage
:hide:

assert np.isclose(np.mean(ligand_dict['torsion']), 0.9038734003286987)
assert np.isclose(np.mean(ligand_dict['binder_angle']), 150.0120482677146)

The printing the average of the collated values for all ligands looks
like:

Expand Down Expand Up @@ -214,6 +221,12 @@ molecule.
centroids = analyser.get_building_block_centroids(apdcage)
# Out: {0: array([8.92788038, 0.41529785, 0.49671345]), ...}

.. testcode:: analysing-cage
:hide:

assert np.allclose(
centroids[0], np.array([9.15025292, 0.20886534, 0.45632129])
)

We can get measures of pore size and cage geometry.

Expand Down Expand Up @@ -241,6 +254,11 @@ We can get measures of pore size and cage geometry.
avg_n_pd_bond_length = np.mean(analyser.calculate_bonds(apdcage)[("N", "Pd")])
n_pd_n_angles = analyser.calculate_angles(apdcage)[("N", "Pd", "N")]

.. testcode:: analysing-cage
:hide:

assert analyser.get_min_centroid_distance(apdcage) == 6.612215150137052

Giving:

.. code-block::
Expand Down
58 changes: 48 additions & 10 deletions docs/source/molecular.rst
Original file line number Diff line number Diff line change
@@ -1,29 +1,67 @@
Molecular
=========

Atoms, Functional Groups and Molecules
--------------------------------------

.. toctree::
:maxdepth: 1

PositionedAtom <_autosummary/stko.PositionedAtom>
dummy atom (Du) <_autosummary/stko.Du>
MDAnalysis <_autosummary/stko.MDAnalysis>
ZMatrix <_autosummary/stko.ZMatrix>
MoleculeSplitter <_autosummary/stko.MoleculeSplitter>
MoleculeTransformer <_autosummary/stko.MoleculeTransformer>
Network <_autosummary/stko.Network>
Dummy atom (Du) <_autosummary/stko.Du>
UnitCell <_autosummary/stko.UnitCell>
TopologyExtractor <_autosummary/stko.TopologyExtractor>
TopologyInfo <_autosummary/stko.TopologyInfo>
Torsion <_autosummary/stko.Torsion>
TorsionInfo <_autosummary/stko.TorsionInfo>
ThreeSiteFG <_autosummary/stko.functional_groups.ThreeSiteFG>
ThreeSiteFactory <_autosummary/stko.functional_groups.ThreeSiteFactory>


Molecular Analysis
------------------

.. toctree::
:maxdepth: 1

MoleculeSplitter <_autosummary/stko.MoleculeSplitter>
MoleculeTransformer <_autosummary/stko.MoleculeTransformer>
DecomposeMOC <_autosummary/stko.molecule_analysis.DecomposeMOC>
DitopicThreeSiteAnalyser <_autosummary/stko.molecule_analysis.DitopicThreeSiteAnalyser>
ConstructedAnalyser <_autosummary/stko.molecule_analysis.ConstructedAnalyser>


Subgroup Analysis
-----------------

.. toctree::
:maxdepth: 1

Subgroup <_autosummary/stko.molecule_analysis.Subgroup>
SubgroupAnalyser <_autosummary/stko.molecule_analysis.SubgroupAnalyser>
AlkyneAngle <_autosummary/stko.molecule_analysis.AlkyneAngle>
X5Planarity <_autosummary/stko.molecule_analysis.X5Planarity>
C5N1Planarity <_autosummary/stko.molecule_analysis.C5N1Planarity>
C6Planarity <_autosummary/stko.molecule_analysis.C6Planarity>
Subgroup <_autosummary/stko.molecule_analysis.Subgroup>
SubgroupAnalyser <_autosummary/stko.molecule_analysis.SubgroupAnalyser>


Manipulating Topology Graphs
----------------------------

.. toctree::
:maxdepth: 1

TopologyExtractor <_autosummary/stko.TopologyExtractor>
TopologyInfo <_autosummary/stko.TopologyInfo>
UnreactedToplogyGraph <_autosummary/stko.topology_functions.UnreactedTopologyGraph>
NamedIntermediate <_autosummary/stko.topology_functions.NamedIntermediate>
IntermediatePool <_autosummary/stko.topology_functions.IntermediatePool>


Conversion
----------

.. toctree::
:maxdepth: 1

MDAnalysis <_autosummary/stko.MDAnalysis>
ZMatrix <_autosummary/stko.ZMatrix>
Network <_autosummary/stko.Network>
52 changes: 52 additions & 0 deletions examples/intermediates_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import logging
from pathlib import Path

import stk

import stko


def main() -> None:
"""Run the example."""
# Two building blocks you want to react to form a topology graph.
bb1 = stk.BuildingBlock(
smiles="NCCN", functional_groups=(stk.PrimaryAminoFactory(),)
)
bb2 = stk.BuildingBlock(
smiles="O=CC(C=O)C=O", functional_groups=(stk.AldehydeFactory(),)
)

examples_output = Path("out_intermediates")
examples_output.mkdir(parents=True, exist_ok=True)

# Produce a `TopologyGraph` without doing any reactions.
cage_graphs = stko.topology_functions.UnreactedTopologyGraph(
stk.cage.FourPlusSix((bb1, bb2))
)
logging.info(
"there are %s possible reactions",
len(cage_graphs.get_available_reactions()),
)

# With up to N reactions performed.
intermediate_pool = cage_graphs.get_named_intermediates(n=4)
logging.info(
"there are %s structures with n=%s", len(intermediate_pool), 4
)
for named_intermediate in intermediate_pool.intermediates:
named_intermediate.molecule.write(
examples_output / f"{named_intermediate.intermediate_name}.mol"
)

# Now iterate over all possible reactions with varying amounts of
# completeness and get their smiles.
all_possible_smiles = cage_graphs.get_reacted_smiles()
logging.info("there are %s unique smiles", len(all_possible_smiles))


if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(levelname)s | %(message)s",
)
main()
103 changes: 103 additions & 0 deletions examples/out_intermediates/idx0_3x3FG+2x2FG.mol
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

RDKit 3D

0 0 0 0 0 0 0 0 0 0999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 45 44 0 0 0
M V30 BEGIN ATOM
M V30 1 C -1.2134 -0.7006 7.6921 0
M V30 2 C 0.0024 0.0195 8.1532 0
M V30 3 C 1.2289 -0.7128 7.6921 0
M V30 4 C -0.0155 1.4134 7.6921 0
M V30 5 O -0.9554 1.8112 7.0270 0
M V30 6 H -1.4106 -0.8660 6.6467 0
M V30 7 H 0.0228 0.0328 9.2640 0
M V30 8 H 1.3779 -0.8508 6.6158 0
M V30 9 H 0.7696 2.1271 7.9093 0
M V30 10 C -6.6851 -3.8596 -1.2430 0
M V30 11 C -6.6459 -3.8550 -2.7289 0
M V30 12 C -6.6921 -2.4414 -3.2314 0
M V30 13 O -7.5962 -2.0548 -3.9611 0
M V30 14 C -5.4646 -4.5773 -3.2177 0
M V30 15 O -4.6918 -5.0716 -2.4160 0
M V30 16 H -5.9270 -3.3704 -0.6555 0
M V30 17 H -7.5451 -4.3758 -3.1221 0
M V30 18 H -5.8930 -1.7560 -2.9293 0
M V30 19 H -5.2299 -4.7022 -4.2675 0
M V30 20 C 6.6851 -3.8596 -1.2430 0
M V30 21 C 6.6615 -3.8280 -2.7289 0
M V30 22 C 5.4604 -4.5748 -3.2314 0
M V30 23 O 5.5776 -5.5511 -3.9611 0
M V30 24 C 6.6963 -2.4438 -3.2177 0
M V30 25 O 6.7381 -1.5274 -2.4160 0
M V30 26 H 5.8824 -3.4478 -0.6555 0
M V30 27 H 7.5621 -4.3463 -3.1221 0
M V30 28 H 4.4673 -4.2255 -2.9293 0
M V30 29 H 6.6872 -2.1781 -4.2675 0
M V30 30 N -3.2178 -1.8578 4.4191 0
M V30 31 C -4.6051 -2.2313 4.4421 0
M V30 32 C -4.9290 -3.2079 3.3152 0
M V30 33 N -4.6808 -2.7024 2.0300 0
M V30 34 H -5.2477 -1.3300 4.3651 0
M V30 35 H -4.7784 -2.7831 5.3911 0
M V30 36 H -4.2388 -4.0831 3.4884 0
M V30 37 H -5.9702 -3.5517 3.4212 0
M V30 38 N 3.2255 -1.8639 4.4191 0
M V30 39 C 4.2425 -2.8787 4.4421 0
M V30 40 C 5.2503 -2.6710 3.3153 0
M V30 41 N 4.6885 -2.7085 2.0300 0
M V30 42 H 3.7830 -3.8858 4.3649 0
M V30 43 H 4.8069 -2.7532 5.3911 0
M V30 44 H 5.6634 -1.6358 3.4886 0
M V30 45 H 6.0684 -3.4011 3.4212 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 1 1 2
M V30 2 1 2 3
M V30 3 1 2 4
M V30 4 2 4 5
M V30 5 1 1 6
M V30 6 1 2 7
M V30 7 1 3 8
M V30 8 1 4 9
M V30 9 1 10 11
M V30 10 1 11 12
M V30 11 2 12 13
M V30 12 1 11 14
M V30 13 2 14 15
M V30 14 1 10 16
M V30 15 1 11 17
M V30 16 1 12 18
M V30 17 1 14 19
M V30 18 1 20 21
M V30 19 1 21 22
M V30 20 2 22 23
M V30 21 1 21 24
M V30 22 2 24 25
M V30 23 1 20 26
M V30 24 1 21 27
M V30 25 1 22 28
M V30 26 1 24 29
M V30 27 1 30 31
M V30 28 1 31 32
M V30 29 1 32 33
M V30 30 1 31 34
M V30 31 1 31 35
M V30 32 1 32 36
M V30 33 1 32 37
M V30 34 1 38 39
M V30 35 1 39 40
M V30 36 1 40 41
M V30 37 1 39 42
M V30 38 1 39 43
M V30 39 1 40 44
M V30 40 1 40 45
M V30 41 2 1 30
M V30 42 2 10 33
M V30 43 2 3 38
M V30 44 2 20 41
M V30 END BOND
M V30 END CTAB
M END

$$$$
Loading

0 comments on commit a57cec0

Please sign in to comment.