Skip to content

Commit

Permalink
Merge branch 'main' into cli_yaml_draft
Browse files Browse the repository at this point in the history
  • Loading branch information
IAlibay authored Nov 8, 2023
2 parents aab5620 + 68a08d2 commit 43ef282
Show file tree
Hide file tree
Showing 39 changed files with 1,855 additions and 695 deletions.
22 changes: 22 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributing to OpenFE

Thanks for contributing to the OpenFE software project!
Read our [code of conduct](../Code_of_Conduct.md) to understand the standards you must adhere to.

## Questions

If you have any questions on using the OpenFE package, reach out on the "Discussions" tab above to start a conversation!
We are happy to get you started in using our software.

## Issues

If you think you have encountered a software issue, please raise this on the "Issues" tab in Github.
In general the more details you can provide the better,
we recommend reading section 3.3 of [this article](https://livecomsjournal.org/index.php/livecoms/article/view/v3i1e1473)
to understand the problem solving process.

## Contributing

We welcome any fixes or code contributions.
Note that any contributions made must be made under a MIT license.
Feel free to reach out to the developer team who can assist you in this process.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
env:
# Set the OFE_SLOW_TESTS to True if running a Cron job
OFE_SLOW_TESTS: ${{ fromJSON('{"false":"false","true":"true"}')[github.event_name != 'pull_request'] }}
DUECREDIT_ENABLE: 'yes'
run: |
pytest -n auto -v --cov=openfe --cov=openfecli --cov-report=xml --durations=10
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# custom ignores
.duecredit.p
.xxrun
.idea/
.vscode/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Logo](https://img.shields.io/badge/OSMF-OpenFreeEnergy-%23002f4a)](https://openfree.energy/)
[![build](https://github.com/OpenFreeEnergy/openfe/actions/workflows/ci.yaml/badge.svg)](https://github.com/OpenFreeEnergy/openfe/actions/workflows/ci.yaml)
[![build](https://github.com/OpenFreeEnergy/openfe/actions/workflows/ci.yaml/badge.svg?event=schedule)](https://github.com/OpenFreeEnergy/openfe/actions/workflows/ci.yaml)
[![coverage](https://codecov.io/gh/OpenFreeEnergy/openfe/branch/main/graph/badge.svg)](https://codecov.io/gh/OpenFreeEnergy/openfe)
[![documentation](https://readthedocs.org/projects/openfe/badge/?version=latest)](https://openfe.readthedocs.io/en/latest/?badge=latest)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8344248.svg)](https://doi.org/10.5281/zenodo.8344248)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@

autodoc_mock_imports = [
"matplotlib",
"lomap",
"openmmtools",
"mdtraj",
"openmmforcefields",
Expand Down Expand Up @@ -137,6 +136,7 @@
}
],
"accent_color": "DarkGoldenYellow",
"navigation_with_keys": False,
}
html_logo = "_static/Squaredcircle.svg"

Expand Down
1 change: 1 addition & 0 deletions docs/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ channels:
- https://conda.anaconda.org/conda-forge
dependencies:
- autodoc-pydantic<2.0
- lomap2>=3.0.0
- openff-models>=0.0.5
- openff-toolkit >=0.13.0
- openff-units
Expand Down
7 changes: 5 additions & 2 deletions docs/reference/api/ligand_network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Functions that build a :class:`.LigandNetwork` from a collection of :class:`Smal
generate_radial_network
generate_maximal_network
generate_minimal_spanning_network
generate_minimal_redundant_network
generate_lomap_network


.. _Ligand Network Loaders:

Expand Down Expand Up @@ -90,15 +93,15 @@ Atom Map Scorers

Scoring functions for a mapping between ligands. These are used as objective functions for :any:`Ligand Network Planners`.

LOMAP Scorers

Lomap Scorers
~~~~~~~~~~~~~

Scorers implemented by the `LOMAP <https://github.com/OpenFreeEnergy/Lomap>`_ package.

.. apparently we need the atom_mapping because internally autofunction is
trying ``import openfe.setup.lomap_scorers``, which doesn't work (whereas
``from openfe.setup import lomap_scorers`` does)
.. module:: openfe.setup.atom_mapping.lomap_scorers

.. autosummary::
Expand Down
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ channels:
- jaimergp/label/unsupported-cudatoolkit-shim
- conda-forge
dependencies:
- duecredit
- lomap2>=3.0.0
- numpy<1.24
- networkx
- rdkit
Expand Down
Binary file added openfe/.duecredit.p
Binary file not shown.
74 changes: 74 additions & 0 deletions openfe/due.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# emacs: at the end of the file
# ex: set sts=4 ts=4 sw=4 et:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
"""
Stub file for a guaranteed safe import of duecredit constructs: if duecredit
is not available.
To use it, place it into your project codebase to be imported, e.g. copy as
cp stub.py /path/tomodule/module/due.py
Note that it might be better to avoid naming it duecredit.py to avoid shadowing
installed duecredit.
Then use in your code as
from .due import due, Doi, BibTeX, Text
See https://github.com/duecredit/duecredit/blob/master/README.md for examples.
Origin: Originally a part of the duecredit
Copyright: 2015-2021 DueCredit developers
License: BSD-2
"""

__version__ = '0.0.9'


class InactiveDueCreditCollector(object):
"""Just a stub at the Collector which would not do anything"""
def _donothing(self, *args, **kwargs):
"""Perform no good and no bad"""
pass

def dcite(self, *args, **kwargs):
"""If I could cite I would"""
def nondecorating_decorator(func):
return func
return nondecorating_decorator

active = False
activate = add = cite = dump = load = _donothing

def __repr__(self):
return self.__class__.__name__ + '()'


def _donothing_func(*args, **kwargs):
"""Perform no good and no bad"""
pass


try:
from duecredit import due, BibTeX, Doi, Url, Text # lgtm [py/unused-import]
if 'due' in locals() and not hasattr(due, 'cite'):
raise RuntimeError(
"Imported due lacks .cite. DueCredit is now disabled")
except Exception as e:
if not isinstance(e, ImportError):
import logging
logging.getLogger("duecredit").error(
"Failed to import duecredit due to %s" % str(e))
# Initiate due stub
due = InactiveDueCreditCollector()
BibTeX = Doi = Url = Text = _donothing_func

# Emacs mode definitions
# Local Variables:
# mode: python
# py-indent-offset: 4
# tab-width: 4
# indent-tabs-mode: nil
# End:
55 changes: 34 additions & 21 deletions openfe/protocols/openmm_afe/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import openmm
from openff.units import unit
from openff.units.openmm import from_openmm, to_openmm, ensure_quantity
from openff.toolkit.topology import Molecule as OFFMolecule
from openmmtools import multistate
from openmmtools.states import (SamplerState,
ThermodynamicState,
Expand Down Expand Up @@ -71,7 +72,7 @@ def __init__(self, *,
stateA: ChemicalSystem,
stateB: ChemicalSystem,
settings: settings.Settings,
alchemical_components: Dict[str, List[str]],
alchemical_components: dict[str, list[Component]],
generation: int = 0,
repeat_id: int = 0,
name: Optional[str] = None,):
Expand All @@ -89,6 +90,8 @@ def __init__(self, *,
constructed by calling the
:class:`AbsoluteTransformProtocol.get_default_settings` method
to get a default set of settings.
alchemical_components : dict[str, Component]
the alchemical components for each state in this Unit
name : str, optional
Human-readable identifier for this Unit
repeat_id : int, optional
Expand All @@ -110,24 +113,24 @@ def __init__(self, *,

@staticmethod
def _get_alchemical_indices(omm_top: openmm.Topology,
comp_resids: Dict[str, npt.NDArray],
alchem_comps: Dict[str, List[Component]]
) -> List[int]:
comp_resids: dict[Component, npt.NDArray],
alchem_comps: dict[str, list[Component]]
) -> list[int]:
"""
Get a list of atom indices for all the alchemical species
Parameters
----------
omm_top : openmm.Topology
Topology of OpenMM System.
comp_resids : Dict[str, npt.NDArray]
comp_resids : dict[Component, npt.NDArray]
A dictionary of residues for each component in the System.
alchem_comps : Dict[str, List[Component]]
alchem_comps : dict[str, list[Component]]
A dictionary of alchemical components for each end state.
Return
------
atom_ids : List[int]
atom_ids : list[int]
A list of atom indices for the alchemical species
"""

Expand Down Expand Up @@ -208,7 +211,10 @@ def _set_optional_path(basepath):
self.shared_basepath = _set_optional_path(shared_basepath)

@abc.abstractmethod
def _get_components(self):
def _get_components(self) -> tuple[dict[str, list[Component]],
Optional[gufe.SolventComponent],
Optional[gufe.ProteinComponent],
dict[SmallMoleculeComponent, OFFMolecule]]:
"""
Get the relevant components to create the alchemical system with.
Expand Down Expand Up @@ -280,7 +286,7 @@ def _get_modeller(
self,
protein_component: Optional[ProteinComponent],
solvent_component: Optional[SolventComponent],
smc_components: list[SmallMoleculeComponent],
smc_components: dict[SmallMoleculeComponent, OFFMolecule],
system_generator: SystemGenerator,
solvation_settings: SolvationSettings
) -> tuple[app.Modeller, dict[Component, npt.NDArray]]:
Expand All @@ -294,8 +300,8 @@ def _get_modeller(
Protein Component, if it exists.
solvent_component : Optional[ProteinCompoinent]
Solvent Component, if it exists.
smc_components : list[SmallMoleculeComponents]
List of SmallMoleculeComponents to add.
smc_components : list[openff.toolkit.topology.Molecule]
List of openff Molecules to add.
system_generator : openmmforcefields.generator.SystemGenerator
System Generator to parameterise this unit.
solvation_settings : SolvationSettings
Expand All @@ -317,10 +323,17 @@ def _get_modeller(
# of solvating the system.
# Note by default this is cached to ctx.shared/db.json which should
# reduce some of the costs.
for comp in smc_components:
offmol = comp.to_openff()
for mol in smc_components.values():
# don't do this if we have user charges
if not (mol.partial_charges is not None and np.any(mol.partial_charges)):
# due to issues with partial charge generation in ambertools
# we default to using the input conformer for charge generation
mol.assign_partial_charges(
'am1bcc', use_conformers=mol.conformers
)

system_generator.create_system(
offmol.to_topology().to_openmm(), molecules=[offmol]
mol.to_topology().to_openmm(), molecules=[mol]
)

# get OpenMM modeller + dictionary of resids for each component
Expand All @@ -338,7 +351,7 @@ def _get_omm_objects(
self,
system_modeller: app.Modeller,
system_generator: SystemGenerator,
smc_components: list[SmallMoleculeComponent],
smc_components: list[OFFMolecule],
) -> tuple[app.Topology, openmm.unit.Quantity, openmm.System]:
"""
Get the OpenMM Topology, Positions and System of the
Expand All @@ -351,8 +364,8 @@ def _get_omm_objects(
parametrized.
system_generator : SystemGenerator
SystemGenerator object to create a System with.
smc_components : list[SmallMoleculeComponent]
A list of SmallMoleculeComponents to add to the system.
smc_components : list
A list of openff Molecules to add to the system.
Returns
-------
Expand All @@ -368,7 +381,7 @@ def _get_omm_objects(
positions = to_openmm(from_openmm(system_modeller.getPositions()))
system = system_generator.create_system(
system_modeller.topology,
molecules=[s.to_openff() for s in smc_components]
molecules=smc_components,
)
return topology, system, positions

Expand Down Expand Up @@ -551,7 +564,7 @@ def _get_reporter(
)

nc = self.shared_basepath / simulation_settings.output_filename
chk = self.shared_basepath / simulation_settings.checkpoint_storage
chk = simulation_settings.checkpoint_storage

reporter = multistate.MultiStateReporter(
storage=nc,
Expand Down Expand Up @@ -841,7 +854,7 @@ def run(self, dry=False, verbose=True,

# 5. Get OpenMM topology, positions and system
omm_topology, omm_system, positions = self._get_omm_objects(
system_modeller, system_generator, smc_comps
system_modeller, system_generator, list(smc_comps.values())
)

# 6. Pre-minimize System (Test + Avoid NaNs)
Expand Down Expand Up @@ -915,7 +928,7 @@ def run(self, dry=False, verbose=True,

if not dry:
nc = self.shared_basepath / settings['simulation_settings'].output_filename
chk = self.shared_basepath / settings['simulation_settings'].checkpoint_storage
chk = settings['simulation_settings'].checkpoint_storage

Check warning on line 931 in openfe/protocols/openmm_afe/base.py

View check run for this annotation

Codecov / codecov/patch

openfe/protocols/openmm_afe/base.py#L931

Added line #L931 was not covered by tests
return {
'nc': nc,
'last_checkpoint': chk,
Expand Down
Loading

0 comments on commit 43ef282

Please sign in to comment.