Skip to content

Commit a64135f

Browse files
committed
Using gufe get typed components API
1 parent 2896683 commit a64135f

File tree

3 files changed

+57
-51
lines changed

3 files changed

+57
-51
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "47736a8f-7446-4600-b06d-4c8ffd05f66c",
6+
"metadata": {},
7+
"source": [
8+
"TODO:\n",
9+
"Add a tutorial here on how to use the protein-mutation capabilities in `FEFlow`.\n",
10+
"\n",
11+
"What should it have?\n",
12+
"* How to mutate a protein from a PDB file with `pdbfixer`\n",
13+
"* How to create the mapping between the WT and MUT\n",
14+
" * check mapping is correct (sanity check)\n",
15+
"* Setting up the protocol\n",
16+
"* Executing the protocol"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"id": "fa00a848-79a2-46c3-a141-6e24ce0f7f4f",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": []
26+
}
27+
],
28+
"metadata": {
29+
"kernelspec": {
30+
"display_name": "Python 3 (ipykernel)",
31+
"language": "python",
32+
"name": "python3"
33+
},
34+
"language_info": {
35+
"codemirror_mode": {
36+
"name": "ipython",
37+
"version": 3
38+
},
39+
"file_extension": ".py",
40+
"mimetype": "text/x-python",
41+
"name": "python",
42+
"nbconvert_exporter": "python",
43+
"pygments_lexer": "ipython3",
44+
"version": "3.12.9"
45+
}
46+
},
47+
"nbformat": 4,
48+
"nbformat_minor": 5
49+
}

feflow/protocols/nonequilibrium_cycling.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,16 @@ def _execute(self, ctx, *, protocol, state_a, state_b, mapping, **inputs):
138138
)
139139
from feflow.utils.hybrid_topology import HybridTopologyFactory
140140
from feflow.utils.charge import get_alchemical_charge_difference
141-
from feflow.utils.misc import (
142-
get_typed_components,
143-
register_ff_parameters_template,
144-
)
141+
from feflow.utils.misc import register_ff_parameters_template
145142

146143
# Check compatibility between states (same receptor and solvent)
147144
self._check_states_compatibility(state_a, state_b)
148145

149146
# Get receptor components from systems if found (None otherwise)
150-
solvent_comps = get_typed_components(
151-
state_a, SolventComponent
152-
) # this returns a set
153-
solvent_comp_a = (
154-
solvent_comps.pop() if solvent_comps else None
155-
) # Get the first component if exists
156-
protein_comps_a = get_typed_components(state_a, ProteinComponent)
157-
small_mols_a = get_typed_components(state_a, SmallMoleculeComponent)
147+
solvent_comps = state_a.get_components_of_type(SolventComponent)
148+
solvent_comp_a = solvent_comps.pop() if solvent_comps else None # there must be at most one solvent comp
149+
protein_comps_a = state_a.get_components_of_type(ProteinComponent)
150+
small_mols_a = state_a.get_components_of_type(SmallMoleculeComponent)
158151

159152
# Get alchemical components
160153
alchemical_comps = get_alchemical_components(state_a, state_b)
@@ -187,10 +180,9 @@ def _execute(self, ctx, *, protocol, state_a, state_b, mapping, **inputs):
187180
# Parameterizing small molecules
188181
self.logger.info("Parameterizing molecules")
189182
# Get small molecules from states
190-
# TODO: Refactor if/when gufe provides the functionality https://github.com/OpenFreeEnergy/gufe/issues/251
191-
state_a_small_mols = get_typed_components(state_a, SmallMoleculeComponent)
192-
state_b_small_mols = get_typed_components(state_b, SmallMoleculeComponent)
193-
all_small_mols = state_a_small_mols | state_b_small_mols
183+
state_a_small_mols = state_a.get_components_of_type(SmallMoleculeComponent)
184+
state_b_small_mols = state_b.get_components_of_type(SmallMoleculeComponent)
185+
all_small_mols = set(state_a_small_mols) | set(state_b_small_mols)
194186

195187
# Generate and register FF parameters in the system generator template
196188
all_openff_mols = [comp.to_openff() for comp in all_small_mols]

feflow/utils/misc.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,6 @@
88
import openmm.app
99

1010

11-
# TODO: should this be a method for the gufe.ChemicalSystem class?
12-
def get_typed_components(
13-
system: gufe.ChemicalSystem, comptype: type[gufe.Component]
14-
) -> set[gufe.Component]:
15-
"""
16-
Retrieve all components of a specific type from a `gufe.ChemicalSystem`.
17-
18-
This function searches the components within the provided chemical system
19-
and returns a list of all components matching the specified type.
20-
21-
Parameters
22-
----------
23-
system : gufe.ChemicalSystem
24-
The chemical system from which to extract components.
25-
comptype : Type[gufe.Component]
26-
The type of component to search for, such as `ProteinComponent`,
27-
`SmallMoleculeComponent`, or `SolventComponent`.
28-
29-
Returns
30-
-------
31-
set[gufe.Component]
32-
A set of unique components matching the specified type. If no components
33-
of the given type are found, an empty set is returned.
34-
35-
"""
36-
if not issubclass(comptype, gufe.Component):
37-
raise TypeError(
38-
f"`comptype` must be a subclass of `gufe.Component`. Got: {comptype}"
39-
)
40-
41-
ret_comps = {comp for comp in system.values() if isinstance(comp, comptype)}
42-
43-
return ret_comps
44-
45-
4611
def register_ff_parameters_template(system_generator, charge_settings, openff_mols):
4712
"""
4813
Register force field parameters in the system generator using provided charge settings

0 commit comments

Comments
 (0)