GUFE Components#

Component base class#

class gufe.components.Component(*args, **kwargs)#

Base class for members of a ChemicalSystem.

abstract property name: str#
abstract property total_charge: int | None#

Net formal charge for the Component, if defined.

Small Molecule Component#

class gufe.components.SmallMoleculeComponent(rdkit: rdkit.Chem.rdchem.Mol, name: str = '')#

Component representing a small molecule.

Note

This class is a read-only representation of a molecule, if you want to edit the molecule do this in an appropriate toolkit before creating an instance from this class.

This class supports reading/writing to the .sdf format, which is suited to smaller molecules. Ligands alchemically mutated in a free energy calculation are typically represented with this class.

The name can be explicitly set by the name attribute, or implicitly set based on the tags in the input molecular representation (if supported, as with RDKit). If not explicitly set on creation, the molecule will first look for an OpenFE-specific tag ofe-name, and if that doesn’t exist, for a commonly-used naming tag (e.g., the _Name property for RDKit molecules). If no name is found, the empty string is used.

Parameters:
  • rdkit (rdkit.Chem.rdchem.Mol) – rdkit representation of the molecule

  • name (str, optional) – A human readable tag for this molecule. This name will be used in the hash.

to_sdf() str#

Create a string based on SDF.

See also

from_sdf_string()

create an object from the output of this

classmethod from_sdf_string(sdf_str: str)#

Create SmallMoleculeComponent from SDF-formatted string.

Parameters:

sdf_str (str) – input string in SDF format

Returns:

the deserialized molecule

Return type:

SmallMoleculeComponent

classmethod from_sdf_file(filename: str)#

Create SmallMoleculeComponent from SDF file.

Parameters:

filename (str) – name of SDF file

Returns:

the deserialized molecule

Return type:

SmallMoleculeComponent

to_openff()#

OpenFF Toolkit representation of this molecule

classmethod from_openff(openff, name: str = '')#

Construct from an OpenFF toolkit Molecule

copy_with_replacements(**replacements)#

Make a modified copy of this object.

Since GufeTokenizables are immutable, this is essentially a shortcut to mutate the object. Note that the keyword arguments it takes are based on keys of the dictionaries used in the the _to_dict/_from_dict cycle for this object; in most cases that is the same as parameters to __init__, but not always.

This will always return a new object in memory. So using obj.copy_with_replacements() (with no keyword arguments) is a way to create a shallow copy: the object is different in memory, but its attributes will be the same objects in memory as the original.

Parameters:

replacements (Dict) – keyword arguments with keys taken from the keys given by the output of this object’s to_dict method.

classmethod from_json(json_str)#
classmethod from_rdkit(rdkit: rdkit.Chem.rdchem.Mol, name: str = '')#

Create a Component, copying from an RDKit Mol

property name: str#
property smiles: str#
to_json()#
to_rdkit() rdkit.Chem.rdchem.Mol#

Return an RDKit copied representation of this molecule

property total_charge#

Net formal charge for the Component, if defined.

Protein Component#

class gufe.components.ProteinComponent(rdkit: rdkit.Chem.rdchem.Mol, name='')#

Component representing the contents of a PDB file, such as a protein.

In comparison to a SmallMoleculeComponent, this representation additionally contains information relating to the residue and chain information. This is achievable by having the MonomerInfo attributes present on each atom of the input RDKit molecule, which is done when reading from either PDB or .mae file inputs.

Note

This class is a read-only representation of a protein, if you want to edit the molecule do this in an appropriate toolkit before creating an instance from this class.

Parameters:
  • rdkit (rdkit.Mol) – rdkit representation of the protein

  • name (str, optional) – of the protein, by default “”

classmethod from_pdb_file(pdb_file: str, name: str = '')#

Create ProteinComponent from PDB-formatted file.

Parameters:
  • pdb_file (str) – path to the pdb file.

  • name (str, optional) – name of the input protein, by default “”

Returns:

the deserialized molecule

Return type:

ProteinComponent

classmethod from_pdbx_file(pdbx_file: str, name='')#

Create ProteinComponent from PDBX-formatted file.

Parameters:
  • pdbxfile (str) – path to the pdb file.

  • name (str, optional) – name of the input protein, by default “”

Returns:

the deserialized molecule

Return type:

ProteinComponent

to_openmm_topology() Topology#

Convert to an openmm Topology object

Returns:

resulting topology obj.

Return type:

openmm.app.Topology

to_openmm_positions() Quantity#

serialize the positions to openmm.unit.Quantity ! only one frame at the moment!

Returns:

Quantity containing protein atom positions

Return type:

omm_unit.Quantity

to_pdb_file(out_path: str | bytes | PathLike[str] | PathLike[bytes] | TextIOBase) str#

serialize protein to pdb file.

Parameters:

out_path (Union[str, bytes, PathLike[str], PathLike[bytes], io.TextIOBase]) – provide path or any string based stream (e.g. FileIO ) to the resulting file

Returns:

string path to the resulting pdb.

Return type:

str

to_pdbx_file(out_path: str | bytes | PathLike[str] | PathLike[bytes] | TextIOBase) str#

serialize protein to pdbx file.

Parameters:

out_path (Union[str, bytes, PathLike[str], PathLike[bytes], io.TextIOBase]) – provide path or FileIO to the resulting file

Returns:

string path to the resulting pdbx.

Return type:

str

classmethod from_json(json_str)#
classmethod from_rdkit(rdkit: rdkit.Chem.rdchem.Mol, name: str = '')#

Create a Component, copying from an RDKit Mol

property name: str#
property smiles: str#
to_json()#
to_rdkit() rdkit.Chem.rdchem.Mol#

Return an RDKit copied representation of this molecule

property total_charge#

Net formal charge for the Component, if defined.

Solvent Component#

class gufe.components.SolventComponent(*, smiles: str = 'O', positive_ion: str = 'Na+', negative_ion: str = 'Cl-', neutralize: bool = True, ion_concentration: unit.Quantity = <Quantity(0.15, 'molar')>)#

Component representing solvent molecules in a chemical system.

This component represents the abstract idea of the solvent and ions present around the other components, rather than a list of specific water molecules and their coordinates. This abstract representation is later made concrete by specific MD engine methods.

Parameters:
  • smiles (str, optional) – smiles of the solvent, default ‘O’ (water)

  • positive_ion (str) – the pair of ions which is used to neutralize (if neutralize=True) and bring the solvent to the required ionic concentration. Must be a positive and negative monoatomic ions, defaults “Na+”, “Cl-”

  • negative_ion (str) – the pair of ions which is used to neutralize (if neutralize=True) and bring the solvent to the required ionic concentration. Must be a positive and negative monoatomic ions, defaults “Na+”, “Cl-”

  • neutralize (bool, optional) – if the net charge on the chemical state is neutralized by the ions in this solvent component. Default True

  • ion_concentration (openff-units.unit.Quantity, optional) – ionic concentration required, default 0.15 * unit.molar this must be supplied with units, e.g. “1.5 * unit.molar”

Examples

To create a sodium chloride solution at 0.2 molar concentration:

>>> s = SolventComponent(position_ion='Na', negative_ion='Cl',
...                      ion_concentration=0.2 * unit.molar)
property name: str#
property smiles: str#

SMILES representation of the solvent molecules

property positive_ion: str | None#

The cation in the solvent state

property negative_ion: str | None#

The anion in the solvent state

property neutralize: bool#

If the solvent neutralizes the system overall

property ion_concentration: Quantity#

Concentration of ions in the solvent state

property total_charge#

Solvents don’t have a formal charge defined so this returns None

Chemical System#

class gufe.chemicalsystem.ChemicalSystem(components: Dict[str, Component], name: str | None = '')#

A node of an alchemical network; represents a system of chemicals.

Create a node for an alchemical network.

Parameters:
  • components – The molecular representation of the chemical state, including connectivity and coordinates. Given as a dict with user-defined labels as keys, Components as values.

  • name – Optional identifier for the chemical state; included with the other attributes as part of the (hashable) graph node itself when the chemical state is added to an AlchemicalNetwork.

property components: dict[str, Component]#

The molecular representation of the chemical system.

Components include atomic connectivity and coordinates. This is a frozendict with user-defined labels as keys and Component instances as values.

property name#

Optional identifier for the chemical system.

Used as part of the (hashable) graph node itself when the chemical state is added to an AlchemicalNetwork.

property total_charge#

Formal charge for the ChemicalSystem.

classmethod as_protein_smallmolecule_solvent()#
classmethod as_smallmolecule_solvent()#