Skip to content

Commit

Permalink
auto format all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemhenry committed Nov 22, 2024
1 parent 82cb73d commit 69eebc7
Show file tree
Hide file tree
Showing 78 changed files with 3,785 additions and 2,831 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
pydantic-version: [">1"]
python-version:
- "3.10"
- "3.11"
- "3.11"
- "3.12"
include:
# Note: pinned to macos-12
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/clean_cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
Expand Down
18 changes: 9 additions & 9 deletions devtools/raise-or-close-issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
# - TITLE: A string title which the issue will have.

import os
from github import Github

from github import Github

if __name__ == "__main__":
git = Github(os.environ['GITHUB_TOKEN'])
status = os.environ['CI_OUTCOME']
repo = git.get_repo('OpenFreeEnergy/gufe')
title = os.environ['TITLE']
git = Github(os.environ["GITHUB_TOKEN"])
status = os.environ["CI_OUTCOME"]
repo = git.get_repo("OpenFreeEnergy/gufe")
title = os.environ["TITLE"]

target_issue = None
for issue in repo.get_issues():
if issue.title == title:
target_issue = issue

# Close any issues with given title if CI returned green
if status == 'success':
if status == "success":
if target_issue is not None:
target_issue.edit(state='closed')
target_issue.edit(state="closed")
else:
# Otherwise raise an issue
if target_issue is None:
Expand Down
2 changes: 0 additions & 2 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ v1.1.0
* Fixed an issue where ProtocolDAG DAG order & keys were unstable /
non-deterministic between processes under some circumstances (PR #315).
* Fixed a bug where edge annotations were lost when converting a ``LigandNetwork`` to graphml, all JSON codec types are now supported.


1 change: 0 additions & 1 deletion docs/_static/.gitkeep
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

36 changes: 19 additions & 17 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../'))

sys.path.insert(0, os.path.abspath("../"))


# -- Project information -----------------------------------------------------

project = 'gufe'
copyright = '2022, The OpenFE Development Team'
author = 'The OpenFE Development Team'
project = "gufe"
copyright = "2022, The OpenFE Development Team"
author = "The OpenFE Development Team"


# -- General configuration ---------------------------------------------------
Expand All @@ -28,14 +29,14 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon',
'sphinxcontrib.autodoc_pydantic',
'sphinx.ext.intersphinx',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinxcontrib.autodoc_pydantic",
"sphinx.ext.intersphinx",
]

autoclass_content = 'both'
autoclass_content = "both"

autodoc_default_options = {
"members": True,
Expand All @@ -47,20 +48,21 @@
autosummary_generate = True

intersphinx_mapping = {
'rdkit': ('https://www.rdkit.org/docs/', None),
"rdkit": ("https://www.rdkit.org/docs/", None),
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

autodoc_mock_imports = ["openff.models",
"rdkit",
"networkx",
autodoc_mock_imports = [
"openff.models",
"rdkit",
"networkx",
]


Expand All @@ -77,7 +79,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# replace macros
rst_prolog = """
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Ligand network setup
GUFE defines a basic API for the common case of performing alchemical
transformations between small molecules, either for relative binding free
energies of relative hydration free energies. This handles how mappings
between different molecules are defined for alchemical transformations,
between different molecules are defined for alchemical transformations,
by defining both the :class:`.LigandAtomMapping` object that contains the
details of a specific mapping, and the :class:`.AtomMapper` abstract API for
an object that creates the mappings.
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ classmethod:
.. Using JSON codecs outside of JSON
.. ---------------------------------
.. In a custom recursive storage scheme,
.. In a custom recursive storage scheme,
.. TODO: DWHS wants to write something here that describes how to use the
codecs in your own non-JSON storage scheme. But this is complicated
Expand Down
47 changes: 18 additions & 29 deletions gufe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,29 @@

from importlib.metadata import version

from . import tokenization

from . import visualization

from . import tokenization, visualization
from .chemicalsystem import ChemicalSystem
from .components import (
Component,
SmallMoleculeComponent,
ProteinComponent,
SolventComponent
)

from .chemicalsystem import ChemicalSystem

from .mapping import (
ComponentMapping, # how individual Components relate
AtomMapping, AtomMapper, # more specific to atom based components
LigandAtomMapping,
SmallMoleculeComponent,
SolventComponent,
)

from .settings import Settings

from .protocols import (
from .ligandnetwork import LigandNetwork
from .mapping import AtomMapper # more specific to atom based components
from .mapping import ComponentMapping # how individual Components relate
from .mapping import AtomMapping, LigandAtomMapping
from .network import AlchemicalNetwork
from .protocols import Protocol # description of a method
from .protocols import ProtocolDAG # many Units forming a workflow
from .protocols import ProtocolDAGResult # the collected result of a DAG
from .protocols import ProtocolUnit # the individual step within a method
from .protocols import ProtocolUnitResult # the result of a single Unit
from .protocols import ( # potentially many DAGs together, giving an estimate
Context,
Protocol, # description of a method
ProtocolUnit, # the individual step within a method
ProtocolDAG, # many Units forming a workflow
ProtocolUnitResult, # the result of a single Unit
ProtocolDAGResult, # the collected result of a DAG
ProtocolResult, # potentially many DAGs together, giving an estimate
ProtocolResult,
)

from .transformations import Transformation, NonTransformation

from .network import AlchemicalNetwork
from .ligandnetwork import LigandNetwork
from .settings import Settings
from .transformations import NonTransformation, Transformation

__version__ = version("gufe")
12 changes: 5 additions & 7 deletions gufe/chemicalsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from collections import abc
from typing import Optional

from .tokenization import GufeTokenizable
from .components import Component
from .tokenization import GufeTokenizable


class ChemicalSystem(GufeTokenizable, abc.Mapping):
Expand All @@ -14,14 +14,14 @@ def __init__(
components: dict[str, Component],
name: Optional[str] = "",
):
"""A combination of Components that form a system
r"""A combination of Components that form a system
Containing a combination of :class:`.SmallMoleculeComponent`,
:class:`.SolventComponent` and :class:`.ProteinComponent`, this object
typically represents all the molecules in a simulation box.
Used as a node for an :class:`.AlchemicalNetwork`.
Parameters
----------
components
Expand Down Expand Up @@ -55,9 +55,7 @@ def _to_dict(self):
@classmethod
def _from_dict(cls, d):
return cls(
components={
key: value for key, value in d["components"].items()
},
components={key: value for key, value in d["components"].items()},
name=d["name"],
)

Expand Down Expand Up @@ -86,7 +84,7 @@ def name(self):
def total_charge(self):
"""Formal charge for the ChemicalSystem."""
# This might evaluate the property twice?
#return sum(component.total_charge
# return sum(component.total_charge
# for component in self._components.values()
# if component.total_charge is not None)
total_charge = 0
Expand Down
3 changes: 1 addition & 2 deletions gufe/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""The building blocks for defining systems"""

from .component import Component

from .smallmoleculecomponent import SmallMoleculeComponent
from .proteincomponent import ProteinComponent
from .smallmoleculecomponent import SmallMoleculeComponent
from .solventcomponent import SolventComponent
56 changes: 32 additions & 24 deletions gufe/components/explicitmoleculecomponent.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import json
import numpy as np
import warnings
from rdkit import Chem
from typing import Optional

from .component import Component
import numpy as np
from rdkit import Chem

# typing
from ..custom_typing import RDKitMol
from .component import Component


def _ensure_ofe_name(mol: RDKitMol, name: str) -> str:
Expand All @@ -26,10 +26,7 @@ def _ensure_ofe_name(mol: RDKitMol, name: str) -> str:
pass

if name and rdkit_name and rdkit_name != name:
warnings.warn(
f"Component being renamed from {rdkit_name}"
f"to {name}."
)
warnings.warn(f"Component being renamed from {rdkit_name}" f"to {name}.")
elif name == "":
name = rdkit_name

Expand All @@ -56,21 +53,23 @@ def _check_partial_charges(mol: RDKitMol) -> None:
* If partial charges are found.
* If the partial charges are near 0 for all atoms.
"""
if 'atom.dprop.PartialCharge' not in mol.GetPropNames():
if "atom.dprop.PartialCharge" not in mol.GetPropNames():
return

p_chgs = np.array(
mol.GetProp('atom.dprop.PartialCharge').split(), dtype=float
)
p_chgs = np.array(mol.GetProp("atom.dprop.PartialCharge").split(), dtype=float)

if len(p_chgs) != mol.GetNumAtoms():
errmsg = (f"Incorrect number of partial charges: {len(p_chgs)} "
f" were provided for {mol.GetNumAtoms()} atoms")
errmsg = (
f"Incorrect number of partial charges: {len(p_chgs)} "
f" were provided for {mol.GetNumAtoms()} atoms"
)
raise ValueError(errmsg)

if (sum(p_chgs) - Chem.GetFormalCharge(mol)) > 0.01:
errmsg = (f"Sum of partial charges {sum(p_chgs)} differs from "
f"RDKit formal charge {Chem.GetFormalCharge(mol)}")
errmsg = (
f"Sum of partial charges {sum(p_chgs)} differs from "
f"RDKit formal charge {Chem.GetFormalCharge(mol)}"
)
raise ValueError(errmsg)

# set the charges on the atoms if not already set
Expand All @@ -81,18 +80,24 @@ def _check_partial_charges(mol: RDKitMol) -> None:
else:
atom_charge = atom.GetDoubleProp("PartialCharge")
if not np.isclose(atom_charge, charge):
errmsg = (f"non-equivalent partial charges between atom and "
f"molecule properties: {atom_charge} {charge}")
errmsg = (
f"non-equivalent partial charges between atom and "
f"molecule properties: {atom_charge} {charge}"
)
raise ValueError(errmsg)

if np.all(np.isclose(p_chgs, 0.0)):
wmsg = (f"Partial charges provided all equal to "
"zero. These may be ignored by some Protocols.")
wmsg = (
f"Partial charges provided all equal to "
"zero. These may be ignored by some Protocols."
)
warnings.warn(wmsg)
else:
wmsg = ("Partial charges have been provided, these will "
"preferentially be used instead of generating new "
"partial charges")
wmsg = (
"Partial charges have been provided, these will "
"preferentially be used instead of generating new "
"partial charges"
)
warnings.warn(wmsg)


Expand All @@ -103,6 +108,7 @@ class ExplicitMoleculeComponent(Component):
representations. Specific file formats, such as SDF for small molecules
or PDB for proteins, should be implemented in subclasses.
"""

_rdkit: Chem.Mol
_name: str

Expand All @@ -121,8 +127,10 @@ def __init__(self, rdkit: RDKitMol, name: str = ""):
)

if not any(atom.GetAtomicNum() == 1 for atom in rdkit.GetAtoms()):
warnings.warn("Molecule doesn't have any hydrogen atoms present. "
"If this is unexpected, consider loading the molecule with `removeHs=False`")
warnings.warn(
"Molecule doesn't have any hydrogen atoms present. "
"If this is unexpected, consider loading the molecule with `removeHs=False`"
)

self._rdkit = rdkit
self._smiles: Optional[str] = None
Expand Down
Loading

0 comments on commit 69eebc7

Please sign in to comment.