meeko.molsetup module#
- class meeko.molsetup.UniqAtomParams[source]#
Bases:
objectA helper class used to keep parameters organized in a particular way that lets them be more usable.
- params#
can be thought of as rows
- Type:
list
- param_names#
can be thought of as columns
- Type:
list
- classmethod from_dict(dictionary)[source]#
Creates an UniqAtomParams object, populates it with information from the input dictionary, then returns the new object.
- Parameters:
dictionary (dict) – A dictionary containing the keys “params” and “param_names”, where the value for “params” is parseable as rows and the value for “param_names” contains the corresponding column data.
- Returns:
uap – A populated UniqAtomParams object.
- Return type:
- get_indices_from_atom_params(atom_params)[source]#
Retrieves the indices of specific atom parameters in the UniqAtomParams object.
- Parameters:
atom_params (dict) – A dict with keys that correspond to the param names already in the UniqAtomParams object.
- Returns:
param_idxs – A list of indices corresponding to the order of parameters in the atom_params value lists that indicates the index of that “row” of parameters in UniqAtomParams params.
- Return type:
list
- Raises:
RuntimeError – If the lists in atom_params are not all the same size or if the keys in atom_params do not match the param_names in UniqAtomParams.
- add_parameter(new_param_dict)[source]#
Adds a new parameter to the UniqAtomParams object. If the parameter already exists, it returns the index of the existing parameter.
- Parameters:
new_param_dict (dict) – A dictionary containing the new parameter to be added. The keys should match the param_names in the UniqAtomParams object.
- Returns:
new_row_index – The index of the new parameter in the UniqAtomParams object.
- Return type:
int
- add_molsetup(molsetup, atom_params=None, add_atomic_nr=False, add_atom_type=False)[source]#
Adds a molecule setup to the UniqAtomParams object. This is used to add parameters for each atom in the molecule setup.
- Parameters:
molsetup (MoleculeSetup) – The molecule setup object containing the atoms and their parameters.
atom_params (dict, optional) – A dictionary containing the parameters to be added. If None, the parameters from the molecule setup will be used.
add_atomic_nr (bool, optional) – If True, adds the atomic number to the parameters. Default is False.
add_atom_type (bool, optional) – If True, adds the atom type to the parameters. Default is False.
- Returns:
param_idxs – A list of indices corresponding to the parameters added to the UniqAtomParams object.
- Return type:
list
- class meeko.molsetup.Atom(index, pdbinfo=None, charge=0.0, coord=<factory>, atomic_num=None, atom_type=None, is_ignore=False, graph=<factory>, is_dummy=False, is_pseudo_atom=False)[source]#
Bases:
BaseJSONParsableA class representing an atom in a molecule.
-
index:
int#
-
pdbinfo:
Union[str,PDBAtomInfo] = None#
-
charge:
float= 0.0#
-
coord:
ndarray#
-
atomic_num:
int= None#
-
atom_type:
str= None#
-
is_ignore:
bool= False#
-
graph:
list[int]#
-
is_dummy:
bool= False#
-
is_pseudo_atom:
bool= False#
-
expected_json_keys:
Optional[frozenset[str]] = {'atom_type', 'atomic_num', 'charge', 'coord', 'graph', 'index', 'is_dummy', 'is_ignore', 'is_pseudo_atom', 'pdbinfo'}#
-
index:
- class meeko.molsetup.Bond(index1, index2, rotatable=False, breakable=False)[source]#
Bases:
BaseJSONParsableA class representing a bond between two atoms in a molecule.
-
canon_id:
tuple[int,int]#
-
index1:
int#
-
index2:
int#
-
rotatable:
bool= False#
-
breakable:
bool= False#
-
expected_json_keys:
Optional[frozenset[str]] = {'canon_id', 'index1', 'index2', 'rotatable'}#
- static get_bond_id(idx1, idx2)[source]#
Generates a consistent, “canonical”, bond id from a pair of atom indices in the graph.
- Parameters:
idx1 (int) – atom index of one of the atoms in the bond
idx2 (int) – atom index of the other atom in the bond
- Returns:
canon_id – a tuple of the two indices in their canonical order
- Return type:
tuple
-
canon_id:
- class meeko.molsetup.Ring(ring_id)[source]#
Bases:
BaseJSONParsableA class representing a ring in a molecule.
-
ring_id:
tuple#
-
expected_json_keys:
Optional[frozenset[str]] = {'ring_id'}#
-
ring_id:
- class meeko.molsetup.RingClosureInfo(bonds_removed=<factory>, pseudos_by_atom=<class 'collections.defaultdict'>)[source]#
Bases:
objectA class representing the information about ring closures in a molecule.
-
bonds_removed:
list#
- pseudos_by_atom#
alias of
defaultdict
-
bonds_removed:
- class meeko.molsetup.Restraint(atom_index, target_coords, kcal_per_angstrom_square, delay_angstroms)[source]#
Bases:
BaseJSONParsableA class representing a restraint on an atom in a molecule.
-
atom_index:
int#
-
target_coords:
tuple[float,float,float]#
-
kcal_per_angstrom_square:
float#
-
delay_angstroms:
float#
-
expected_json_keys:
Optional[frozenset[str]] = {'atom_index', 'delay_angstroms', 'kcal_per_angstrom_square', 'target_coords'}#
-
atom_index:
- class meeko.molsetup.MoleculeSetup(name=None)[source]#
Bases:
BaseJSONParsableBase MoleculeSetup Class, provides a way to store information about molecules for a number of purposes.
- name#
The name of the molecule.
- Type:
str
- pseudoatom_count#
The number of pseudoatoms in the molecule.
- Type:
int
- bond_info#
A dictionary mapping tuples of atom indices to Bond objects representing the bonds in the molecule.
- Type:
dict[tuple, Bond]
- rings#
A dictionary mapping tuples of atom indices to Ring objects representing the rings in the molecule.
- Type:
dict
- ring_closure_info#
An object representing the information about ring closures in the molecule.
- Type:
- rotamers#
A list of dictionaries representing the rotamers in the molecule.
- Type:
list[dict]
- atom_params#
A dictionary containing the parameters for the atoms in the molecule.
- Type:
dict
- restraints#
A list of Restraint objects representing the restraints on the atoms in the molecule.
- Type:
list[Restraint]
- flexibility_model#
A dictionary representing the flexibility model of the molecule.
- Type:
dict
- PSEUDOATOM_ATOMIC_NUM = 0#
-
expected_json_keys:
Optional[frozenset[str]] = {'atom_params', 'atoms', 'bond_info', 'flexibility_model', 'name', 'pseudoatom_count', 'restraints', 'ring_closure_info', 'rings', 'rotamers'}#
- add_atom(atom_index=None, overwrite=False, pdbinfo=None, charge=0.0, coord=None, atomic_num=None, atom_type=None, is_ignore=False, graph=None)[source]#
Adds an atom with all the specified attributes to the MoleculeSetup, either at the specified atom index, or by appending it to the internal list of atoms. Default values will be used for any attributes with unspecified values.
- Parameters:
atom_index (int) – The index of the atom in the molecule.
overwrite (bool, optional) – A flag indicating whether to overwrite an existing atom at the specified index. Default is False.
pdbinfo (str) – The PDB information for the atom.
charge (float) – The charge of the atom.
coord (np.ndarray) – The coordinates of the atom in 3D space.
atomic_num (int) – The atomic number of the atom.
atom_type (str) – The type of the atom.
is_ignore (bool) – A flag indicating whether the atom should be ignored.
graph (list[int]) – A list of indices representing the neighboring atoms in the molecule.
- Return type:
None
- Raises:
RuntimeError – If the atom index is specified and it would be trying to overwrite an existing atom in the atom list.
- add_pseudoatom(pdbinfo=None, charge=0.0, coord=None, atom_type=None, is_ignore=False, anchor_list=None, rotatable=False)[source]#
Adds a pseudoatom with all the specified attributes to the MoleculeSetup. Default values will be used for any attributes with unspecified values. Multiple bonds can be specified to support the centroids of aromatic rings. If rotatable, makes the anchor atom rotatable to allow the pseudoatom movement.
- Parameters:
pdbinfo (str) – The PDB information for the atom.
charge (float) – The charge of the atom.
coord (np.ndarray) – The coordinates of the atom in 3D space.
atomic_num (int) – The atomic number of the atom.
atom_type (str) – The type of the atom.
is_ignore (bool) – A flag indicating whether the atom should be ignored.
graph (list[int]) – A list of indices representing the neighboring atoms in the molecule.
anchor_list (list[int]) – a list of ints indicating the multiple bonds that can be specified as input.
rotatable (bool) – flag indicating if the anchor atom should be marked as rotatable to allow the pseudoatom movement.
- Returns:
pseudoatom_index – The atom_index of the added pseudoatom.
- Return type:
int
- Raises:
RuntimeError – When the incorrect number of anchors of pseudoatoms are found in rigid_groups in the flexibility model.
- delete_atom(atom_index)[source]#
Clears the atom data at a specified atom index and replaces the atom with a dummy atom.
- Parameters:
atom_index (int) – atom index to replace with a dummy atom
- Return type:
None
- add_bond(atom_index_1, atom_index_2, rotatable=False)[source]#
Creates a bond and adds it to all the internal data structures where atom bonds are being tracked.
- Parameters:
atom_index_1 (int) – Atom index of one of the atoms in the bond.
atom_index_2 (int) – Atom index of the other atom in the bond.
rotatable (bool) – Indicates whether the bond is rotatable.
- Return type:
None
- Raises:
IndexError – When one or more the given bond atom indices do not exist in the MoleculeSetup.
- delete_bond(atom_index_1, atom_index_2)[source]#
Deletes a bond from the molecule setup.
- Parameters:
atom_index_1 (int) – The atom index of one of the atoms in the bond to delete.
atom_index_2 (int) – The atom index of the other atom in the bond to delete.
- Return type:
None
- add_rotamers(index_list, angle_list)[source]#
Adds rotamers to the internal record of rotamers.
- Parameters:
index_list (list[(int, int, int, int)]) – A list of tuples representing the indices of the atoms involved in the rotamer.
angle_list (np.ndarray) – A numpy array of angles corresponding to the rotamer.
- Return type:
None
- Raises:
RuntimeError – When the bond ID already exists in the rotamers or when the bond is not rotatable.
- delete_rotamers(bond_id_list=None, index_list=None)[source]#
Deletes rotamers from the internal list of rotamers, either by using bond ids or by generating bond ids from a list of input indices.
- Parameters:
bond_id_list (list[tuple]) – A list of tuples representing the bond ids to delete.
index_list (list[(int, int, int, int)]) – A list of tuples representing the indices of the atoms involved in the rotamer.
- Return type:
None
- property true_atom_count#
Counts the number of atoms in the MoleculeSetup that are not pseudo_atoms or marked as dummy atoms
- Returns:
count – The number of atoms currently in the MoleculeSetup that are not dummy atoms or pseudo_atoms.
- Return type:
int
- clean_atoms(remove_pseudoatoms=False)[source]#
Cleans dummy and potentially also pseudoatoms from the MoleculeSetup so only true atoms remain. Note that this is pretty slow and should not be done often.
- Parameters:
remove_pseudoatoms (bool) – Indicates if we want to remove all the pseudoatoms from the MoleculeSetup. Default is False, which means only dummy atoms will be removed.
- Returns:
The number of atoms removed from the MoleculeSetup.
- Return type:
int
- get_pdbinfo(atom_index)[source]#
Retrieves the PDB Info string for the atom with the specified atom index.
- Parameters:
atom_index (int) – Atom index to retrieve data for.
- Returns:
pdbinfo – A string containing the pdb information for the atom.
- Return type:
str
- Raises:
IndexError – When the provided atom index does not exist in the MoleculeSetup or the atom index does not contain data.
- get_charge(atom_index)[source]#
Retrieves the partial charge for the atom with the specified atom index.
- Parameters:
atom_index (int) – Atom index to retrieve data for.
- Returns:
charge – The charge associated with the atom.
- Return type:
float
- Raises:
IndexError – When the provided atom index does not exist in the MoleculeSetup or the atom index does not contain data.
- get_coord(atom_index)[source]#
Retrieves the coordinates for the atom with the specified atom index.
- Parameters:
atom_index (int) – Atom index to retrieve data for.
- Returns:
coord – The coordinates associated with the atom.
- Return type:
np.ndarray
- Raises:
IndexError – When the provided atom index does not exist in the MoleculeSetup or the atom index does not contain data.
- get_atomic_num(atom_index)[source]#
Retrieves the atomic number for the atom with the specified atom index.
- Parameters:
atom_index (int) – Atom index to retrieve data for.
- Returns:
atomic_num – The atomic number associated with an atom.
- Return type:
int
- Raises:
IndexError – When the provided atom index does not exist in the MoleculeSetup or the atom index does not contain data.
- get_atom_type(atom_index)[source]#
Retrieves the atom type for the atom with the specified atom index.
- Parameters:
atom_index (int) – Atom index to retrieve data for.
- Returns:
charge – The atom index associated with the atom.
- Return type:
str
- Raises:
IndexError – When the provided atom index does not exist in the MoleculeSetup or the atom index does not contain data.
- set_atom_type(atom_index, atom_type)[source]#
Sets the atom type for the atom with the specified atom index.
- Parameters:
atom_index (int) – Atom index to set atom_type for.
atom_type (str) – Atom type string to set.
- Return type:
None
- Raises:
IndexError – When the provided atom index does not exist in the MoleculeSetup or the atom index does not contain data.
- set_atom_type_from_uniq_atom_params(uniq_atom_params, prefix)[source]#
Uses a UniqAtomParams object to set the atom_type attribute for atoms in the Molecule Setup object. Adds the specified prefix to each of the atom_type attributes pulled from UniqAtomParams.
- Parameters:
uniq_atom_params (UniqAtomParams) – A uniq atom params object to extract atom_type from.
prefix (str) – A prefix to be appended to all the atom_type attributes.
- Return type:
None
- get_is_ignore(atom_index)[source]#
Retrieves the is_ignore boolean for the atom with the specified atom index.
- Parameters:
atom_index (int) – Atom index to retrieve data for.
- Returns:
is_ignore – Indicates whether a particular atom should be ignored.
- Return type:
bool
- Raises:
IndexError – When the provided atom index does not exist in the MoleculeSetup or the atom index does not contain data.
- get_neighbors(atom_index)[source]#
Retrieves the partial charge for the atom with the specified atom index.
- Parameters:
atom_index (int) – Atom index to retrieve data for.
- Returns:
graph – The graph of the atoms connections to other atoms.
- Return type:
list[int]
- Raises:
IndexError – When the provided atom index does not exist in the MoleculeSetup or the atom index does not contain data.
- merge_terminal_atoms(indices)[source]#
Primarily for merging hydrogens, but will merge the data for any atom or pseudoatom that is bonded to only one other atom.
- Parameters:
indices (list) – A list of indices to merge.
- Return type:
None
- static get_bonds_in_ring(ring)[source]#
Takes as input a tuple of atom indices corresponding to atoms in a ring and returns a list of all the bonds ids in the ring.
- Parameters:
ring (tuple) – A list of atom indices of the atoms in a ring.
- Returns:
bonds – A list of canonical bond id tuples for the bonds in the ring.
- Return type:
list[tuple]
- class meeko.molsetup.MoleculeSetupExternalToolkit[source]#
Bases:
ABCAdditional functions and requirements to extend the MoleculeSetup class in order to use it with external toolkits such as RDKit and OpenBabel.
Required Attributes#
- dihedral_interactionslist
A list of fourier series.
- static are_fourier_series_identical(series1, series2)[source]#
Compares two fourier series represented as lists of dictionaries.
- Parameters:
series1 (list[dict]) – The first fourier series to compare.
series2 (list[dict]) – The second fourier series to compare.
- Returns:
A bool indicicating whether the fourier series are equal.
- Return type:
bool
- add_dihedral_interaction(fourier_series)[source]#
Adds a safe copy of the input fourier series to the dihedral_interactions list if the fourier series is not already in the list.
- Parameters:
fourier_series (list[dict]) – The fourier series to add to the dihedral interactions list.
- Returns:
index – The index of the input fourier series in the dihedral interactions list.
- Return type:
int
- class meeko.molsetup.RDKitMoleculeSetup(name=None, source=None)[source]#
Bases:
MoleculeSetup,MoleculeSetupExternalToolkit,BaseJSONParsableSubclass of MoleculeSetup, used to represent MoleculeSetup objects working with RDKit objects
- mol#
An RDKit Mol object to base the MoleculeSetup on.
- Type:
Chem.Mol
- modified_atom_positions#
List of dictionaries where keys are atom indices, Used to store sets of coordinates, e.g. docked poses, as dictionaries indexed by the atom index, because not all atoms need to have new coordinates specified. Unspecified hydrogen positions bonded to modified heavy atom positions are to be calculated “on-the-fly”.
- Type:
list
- dihedral_interactions#
A list of unique fourier_series, each of which are represented as a list of dictionaries.
- Type:
list
- dihedral_partaking_atoms#
a mapping from tuples of atom indices to the indices in dihedral_interactions
- Type:
dict
- dihedral_labels#
a mapping from tuples of atom indices to dihedral labels
- Type:
dict
- atom_to_ring_id#
mapping of atom index to ring id of each atom belonging to the ring
- Type:
dict
- rmsd_symmetry_indices#
Tuples of the indices of the molecule’s atoms that match a substructure query.
- Type:
tuple
-
dihedral_interactions:
list[dict]#
-
dihedral_partaking_atoms:
dict#
-
dihedral_labels:
dict#
-
expected_json_keys:
Optional[frozenset[str]] = frozenset({'atom_params', 'atom_to_ring_id', 'atoms', 'bond_info', 'dihedral_interactions', 'dihedral_labels', 'dihedral_partaking_atoms', 'flexibility_model', 'modified_atom_positions', 'mol', 'name', 'pseudoatom_count', 'restraints', 'ring_closure_info', 'rings', 'rmsd_symmetry_indices', 'rotamers'})#
- copy()[source]#
Returns a copy of the current RDKitMoleculeSetup.
- Returns:
newsetup – A copy of the current RDKitMoleculeSetup object.
- Return type:
- classmethod from_mol(mol, keep_chorded_rings=False, keep_equivalent_rings=False, compute_gasteiger_charges=True, read_charges_from_prop=None, conformer_id=-1)[source]#
Creates an RDKitMoleculeSetup object from an RDKit Mol object.
- Parameters:
mol (Chem.Mol) – RDKit Mol object to build the RDKitMoleculeSetup from.
keep_chorded_rings (bool, optional) – Indicates whether to keep chorded rings in the molecule. Default is False.
keep_equivalent_rings (bool, optional) – Indicates whether to keep equivalent rings in the molecule. Default is False.
compute_gasteiger_charges (bool, optional) – Indicates whether to compute Gasteiger charges for the molecule. Default is True.
read_charges_from_prop (str, optional) – Indicates whether to read charges from a property in the molecule. Default is None.
conformer_id (int) – The index of the conformer to use. Default is -1, which means the current conformer will be used.
- Returns:
molsetup – A populated RDKitMoleculeSetup object
- Return type:
- Raises:
ValueError – If the RDKit Mol has implicit Hydrogens, or if there are no conformers for the given RDKit Mol, or if the RDKit Mol has multiple fragments, or if the RDKit Mol has a query.
- static remove_elements(mol, to_rm=(12, 20, 25, 26, 30))[source]#
Removes elements from the RDKit molecule and returns the modified molecule.
- Parameters:
mol (Chem.Mol) – The RDKit molecule to modify.
to_rm (tuple, optional) – A tuple of atomic numbers to remove from the molecule. Default is (12, 20, 25, 26, 30).
- Returns:
mol (Chem.Mol) – The modified RDKit molecule.
idx_to_rm (dict) – A dictionary mapping atom indices to their formal charges.
rm_to_neigh (dict) – A dictionary mapping atom indices to their neighbors.
- init_atom(compute_gasteiger_charges, read_charges_from_prop, coords)[source]#
Generates information about the atoms in an RDKit Mol and adds them to an RDKitMoleculeSetup.
- Parameters:
compute_gasteiger_charges (bool) – Indicates whether we should compute gasteiger charges.
coords (list[np.ndarray]) – Atom coordinates for the RDKit Mol.
- Return type:
None
- Raises:
ValueError – If the input for read_charges_from_prop is not a string or is empty, or if the list of charges contains None.
RuntimeError – If the number of atoms in the modified molecule does not match the original molecule.
- init_bond()[source]#
Uses the RDKit mol to initialize bond info for the RDKitMoleculeSetup
- Return type:
None
- find_pattern(smarts)[source]#
Given a SMARTS pattern, finds substruct matches in the molecule.
- Parameters:
smarts (str) – A SMARTS string to find in the RDKit Mol object.
- Returns:
The substruct matches in the RDKit Mol for the given SMARTS.
- Return type:
list[tuple]
- get_mol_name()[source]#
Gets the RDKit Mol’s name from self.mol.
- Returns:
If the mol has a name, returns the name property.
- Return type:
str
- get_smiles_and_order()[source]#
Returns the SMILES string and the mapping between atom indices in the SMILES and self.molof an atom after running RDKit’s RemoveHs function.
- Returns:
smiles (str) – The SMILES string of the molecule.
order (list[int]) – A list of integers representing the mapping between atom indices in the SMILES and self.mol.
- Raises:
RuntimeError – If the number of atoms in the molecule after removing hydrogens does not match the number of atoms in the original molecule.
- perceive_rings(keep_chorded_rings, keep_equivalent_rings)[source]#
Uses Hanser-Jauffret-Kaufmann exhaustive ring detection to find the rings in the molecule.
- Parameters:
keep_chorded_rings (bool) – Indicates whether we want to keep chorded rings.
keep_equivalent_rings (bool) – Indicates whether we want to keep equivalent rings.
- Return type:
None
- get_conformer_with_modified_positions(new_atom_positions)[source]#
Gets a conformer with the specified new atom positions. We operate on one conformer at a time because SetTerminalAtomPositions acts on all conformers of a molecule, and we do not want to guarantee that all conformers require the same set of terminal atoms to be updated.
- Parameters:
new_atom_positions (dict) – The new atom positions we want to use.
- Returns:
new_conformer – A new conformer with the input new atom positions.
- Return type:
Chem.Conformer
- get_mol_with_modified_positions(new_atom_positions_list=None)[source]#
Modifies the stored RDKit Mol to a new set of atom positions, either those provided or the ones stored in self.modified_atom_positions, and returns the modified Mol object.
- Parameters:
new_atom_positions_list (list[dict]) – New atom positions to add to the RDKit Mol object.
- Returns:
new_mol – A new RDKit Mol object with conformers that have the desired new atom positions.
- Return type:
Chem.Mol
- get_num_mol_atoms()[source]#
Gets the number of atoms in the RDKit Mol object.
- Returns:
Number of atoms in the RDKit Mol object.
- Return type:
int
- get_equivalent_atoms()[source]#
Gets the indices of the equivalent atoms in the RDKit Mol object.
- Returns:
A list of indices of the equivalent atoms in the RDKit Mol object.
- Return type:
list[int]
- static get_symmetries_for_rmsd(mol, max_matches=17)[source]#
Finds the symmetry indices for RMSD calculation in the RDKit Mol object.
- Parameters:
mol (Chem.Mol) – The RDKit Mol object to find symmetry indices for.
max_matches (int, optional) – The maximum number of matches to find. Default is 17.
- Returns:
A list of tuples representing the symmetry indices for RMSD calculation.
- Return type:
list[tuple]
- static has_implicit_hydrogens(mol)[source]#
Checks if the RDKit molecule has implicit hydrogens.
- Parameters:
mol (Chem.Mol) – The RDKit molecule to check.
- Returns:
True if the molecule has implicit hydrogens, False otherwise.
- Return type:
bool
- restrain_to(target_mol, kcal_per_angstrom_square=1.0, delay_angstroms=2.0)[source]#
Restrains the current molecule to a target molecule using a stereo isomorphism mapping.
- Parameters:
target_mol (Chem.Mol) – The target RDKit molecule to restrain to.
kcal_per_angstrom_square (float) – The force constant for the restraint.
delay_angstroms (float) – The distance at which the restraint is applied.
- Return type:
None
- Raises:
ImportError – If the misctools module is not available.
-
name:
str#
-
pseudoatom_count:
int#
-
rotamers:
list[dict]#
-
atom_params:
dict#
-
restraints:
list#