Skip to content

Commit

Permalink
Merge pull request #22 from andrewtarzia/scram_dev2
Browse files Browse the repository at this point in the history
Added (WIP) multiple new features for structure exploration, plus some cleaning up.
  • Loading branch information
andrewtarzia authored Jan 18, 2025
2 parents a8f9f4f + 44802a7 commit ae64708
Show file tree
Hide file tree
Showing 54 changed files with 1,230 additions and 675 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,20 @@ 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@v2
- uses: conda-incubator/setup-miniconda@v2
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3

with:
auto-update-conda: true
miniforge-variant: Mambaforge
channels: conda-forge,defaults
miniforge-version: latest
python-version: 3.11
activate-environment: pytest
use-mamba: true

- name: Build environment
run: |
Expand All @@ -68,24 +64,20 @@ jobs:
run: pytest

build-test:
# 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@v2
- uses: conda-incubator/setup-miniconda@v2
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3

with:
auto-update-conda: true
miniforge-variant: Mambaforge
channels: conda-forge,defaults
miniforge-version: latest
python-version: 3.11
activate-environment: buildtest
use-mamba: true

- name: Build environment
run: |
Expand Down
34 changes: 17 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Overview
========

:mod:`cgexplore` or ``cgx`` is a general toolkit built on
``cgexplore`` or ``cgx`` is a general toolkit built on
`stk <https://stk.readthedocs.io/en/stable/>`_ for constructing,
optimising and exploring molecular coarse-grained models.

Expand All @@ -20,7 +20,7 @@ optimising and exploring molecular coarse-grained models.
Installation
============

:mod:`cgexplore` can be installed with pip:
``cgexplore`` can be installed with pip:

.. code-block:: bash
Expand All @@ -33,18 +33,18 @@ With dependancies `openmm <https://openmm.org/>`_ and `openmmtools <https://open
mamba install openmm openmmtools
Then, update directory structure in `env_set.py` if using example code.
Then, update directory structure in ``env_set.py`` if using example code.


The library implements some analysis that uses `Shape 2.1`. Follow the
The library implements some analysis that uses ``Shape 2.1``. Follow the
instructions to download and installed at
`Shape <https://www.iqtc.ub.edu/uncategorised/program-for-the-stereochemical-analysis-of-molecular-fragments-by-means-of-continous-shape-measures-and-associated-tools/>`_


Developer Setup
---------------

To develop with :mod:`cgexplore`, you can clone the repo and use
To develop with ``cgexplore``, you can clone the repo and use
`just <https://github.com/casey/just>`_ to setup the dev environment:

.. code-block:: bash
Expand All @@ -57,7 +57,7 @@ Usage

**To reproduce data in DOI:
`10.1039/D3SC03991A <https://doi.org/10.1039/D3SC03991A>`_**:
Download the source code from `first_paper_example - presubmission`
Download the source code from ``first_paper_example - presubmission``
release from ``Releases``.I do not guarantee that running the example code
on the current version will work. However, with each pull request a test is run
as a GitHub Action connected to this
Expand All @@ -68,26 +68,26 @@ convention has changed and force field xml files should provide the
appropriate information for mapping angles to models.


* The directory `cgexplore` contains the actual source code for the package.
* The directory `first_paper_example` contains the code for `10.1039/D3SC03991A <https://doi.org/10.1039/D3SC03991A>`_.
* `generate_XX.py` generates cage structures for different topology sets
* `env_set.py` sets a specific environment for file outputs
* `plot_XX.py` produces images and figures, and performs analysis
* The directory ``cgexplore`` contains the actual source code for the package.
* The directory ``first_paper_example`` contains the code for `10.1039/D3SC03991A <https://doi.org/10.1039/D3SC03991A>`_.
* ``generate_XX.py`` generates cage structures for different topology sets
* ``env_set.py`` sets a specific environment for file outputs
* ``plot_XX.py`` produces images and figures, and performs analysis

.. important::
**Warning**: If you have a CUDA-capable GPU and attempt to use CUDA in the
first example, you may get `NaN` errors due to the torsion restriction for
first example, you may get ``NaN`` errors due to the torsion restriction for
angles at 180 degrees, which cause problematic forces. This will be handled
in future versions of the code. And logically, I would suggest removing the
torsion restriction for those angles. The `platform` can be handled through
this argument in `build_building_blocks` and `build_populations`, which I
currently set to `None`, meaning `OpenMM` will decide for itself.
torsion restriction for those angles. The ``platform`` can be handled through
this argument in ``build_building_blocks`` and ``build_populations``, which I
currently set to ``None``, meaning ``OpenMM`` will decide for itself.


How To Cite
===========

If you use ``stk`` please cite
If you use ``cgexplore`` please cite

https://github.com/andrewtarzia/CGExplore

Expand All @@ -98,7 +98,7 @@ and
Publications using CGExplore
============================

* Using stk for constructing larger numbers of coarse-grained models: `Systematic exploration of accessible topologies of cage molecules via minimalistic models`__
* Using stk for constructing larger numbers of coarse-grained models: `Systematic exploration of accessible topologies of cage molecules via minimalistic models <https://doi.org/10.1039/D3SC03991A>`_.


Acknowledgements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cgexplore.atomistic.extract\_ditopic\_ensemble
==============================================

.. currentmodule:: cgexplore.atomistic

.. autofunction:: extract_ditopic_ensemble

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cgexplore.atomistic.get\_ditopic\_aligned\_bb
=============================================

.. currentmodule:: cgexplore.atomistic

.. autofunction:: get_ditopic_aligned_bb
3 changes: 2 additions & 1 deletion docs/source/_autosummary/cgexplore.atomistic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ cgexplore.atomistic
:nosignatures:

cgx_optimisation_sequence
extract_ensemble
extract_ditopic_ensemble
get_ditopic_aligned_bb
run_conformer_analysis


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cgexplore.scram.HomolepticTopologyIterator
==========================================
cgexplore.molecular.SixBead
===========================

.. currentmodule:: cgexplore.scram
.. currentmodule:: cgexplore.molecular

.. autoclass:: HomolepticTopologyIterator
.. autoclass:: SixBead
:members:
:inherited-members:
:undoc-members:
Expand Down
25 changes: 25 additions & 0 deletions docs/source/_autosummary/cgexplore.molecular.StericSixBead.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cgexplore.molecular.StericSixBead
=================================

.. currentmodule:: cgexplore.molecular

.. autoclass:: StericSixBead
:members:
:inherited-members:
:undoc-members:
:show-inheritance:




.. rubric:: Methods

.. autosummary::
:nosignatures:







2 changes: 2 additions & 0 deletions docs/source/_autosummary/cgexplore.molecular.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ cgexplore.molecular
LinearPrecursor
Precursor
PrecursorGenerator
SixBead
SpindryConformer
SquarePrecursor
StericSixBead
ThreeC0Arm
ThreeC1Arm
ThreeC2Arm
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cgexplore.scram.BuildingBlockConfiguration
==========================================

.. currentmodule:: cgexplore.scram

.. autoclass:: BuildingBlockConfiguration
:members:
:inherited-members:
:undoc-members:
:show-inheritance:




.. rubric:: Methods

.. autosummary::
:nosignatures:

~BuildingBlockConfiguration.get_building_block_dictionary
~BuildingBlockConfiguration.get_hashable_bbidx_dict





.. rubric:: Attributes

.. autosummary::

~BuildingBlockConfiguration.idx
~BuildingBlockConfiguration.building_block_idx_map
~BuildingBlockConfiguration.building_block_idx_dict


Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ cgexplore.scram.IHomolepticTopologyIterator
.. autosummary::
:nosignatures:

~IHomolepticTopologyIterator.get_graphs
~IHomolepticTopologyIterator.count_graphs
~IHomolepticTopologyIterator.get_num_building_blocks
~IHomolepticTopologyIterator.get_vertex_prototypes
~IHomolepticTopologyIterator.yield_graphs



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cgexplore.scram.get\_custom\_bb\_configurations
===============================================

.. currentmodule:: cgexplore.scram

.. autofunction:: get_custom_bb_configurations
3 changes: 2 additions & 1 deletion docs/source/_autosummary/cgexplore.scram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cgexplore.scram
:template: class.rst
:nosignatures:

BuildingBlockConfiguration
Constructed
HomolepticTopologyIterator
IHomolepticTopologyIterator
TopologyCode
TopologyIterator
Expand All @@ -33,6 +33,7 @@ cgexplore.scram
:toctree:
:nosignatures:

get_custom_bb_configurations
get_potential_bb_dicts
graph_optimise_cage
optimise_cage
Expand Down
29 changes: 6 additions & 23 deletions first_paper_example/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ def analyse_cage(
lig_shape_measures = liga_shape.calculate(l_shape_mol)
l_shape_mol.write(shape_molfile2)

# Always want to extract target torions if present.
g_measure = cgx.analysis.GeomMeasure(
# Always want to extract target torions if present, in toff, they
# are no in the forcefield, so cannot use
# `GeomMeasure.from_forcefield`.
target_torsions=(
cgx.terms.TargetTorsion(
search_string=("b1", "a1", "c1", "a1", "b1"),
Expand Down Expand Up @@ -429,25 +431,6 @@ def xc_map(tstr: str) -> int:
}[tstr]


def stoich_map(tstr: str) -> int:
"""Stoichiometry maps to the number of building blocks."""
return {
"2P3": 5,
"4P6": 10,
"4P62": 10,
"6P9": 15,
"8P12": 20,
"2P4": 6,
"3P6": 9,
"4P8": 12,
"4P82": 12,
"6P12": 18,
"8P16": 24,
"12P24": 36,
"6P8": 14,
}[tstr]


def cltypetopo_to_colormap() -> dict[str, dict]:
"""Convert label."""
return {
Expand Down Expand Up @@ -670,9 +653,9 @@ def data_to_array(json_files, output_dir: pathlib.Path) -> pd.DataFrame:

if row["optimised"]:
row["strain_energy"] = res_dict["fin_energy_kjmol"]
row["energy_per_bb"] = res_dict["fin_energy_kjmol"] / stoich_map(
t_str
)
row["energy_per_bb"] = res_dict[
"fin_energy_kjmol"
] / cgx.topologies.stoich_map(t_str)
for force_title in res_dict["fin_energy_decomp"]:
if force_title in (
"CMMotionRemover_kJ/mol",
Expand Down
3 changes: 1 addition & 2 deletions first_paper_example/plot_cages.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,7 @@ def webapp_csv(
logging.info("running webapp_csv")

github_base_url = (
"https://github.com/andrewtarzia/cgmodels/blob/main/"
"cg_model_jul2023/"
"https://github.com/andrewtarzia/cgmodels/blob/main/cg_model_jul2023/"
)
github_selfsort_url = github_base_url + "self_sort_outcomes/"

Expand Down
Loading

0 comments on commit ae64708

Please sign in to comment.