pygen_structures.charmm_containers module

Module which stores classes intended to deal with CHARMM forcefield data.

class pygen_structures.charmm_containers.CHARMMParameterFile(bonds: (<class 'set'>, None) = None, angles: (<class 'set'>, None) = None, dihedrals: (<class 'set'>, None) = None, impropers: (<class 'set'>, None) = None, cross_maps: (<class 'set'>, None) = None)

Bases: object

A parser for CHARMM PRM files. Used for checking that parameters exist for generated structures.

This class does not contain the values for the parameters, but does ensure that the parameters themselves are present.

Parameters
  • bonds – set of tuples containing 2 atom_type

  • angles – set of tuples containing 3 atom_type

  • dihedrals – set of tuples containing 4 atom_type

  • impropers – set of tuples containing 4 atom_type

  • cross_maps – set of tuples containing 8 atom_type

check_parameters(molecule) → bool

Check a finalized Molecule to verify that all the parameters in the CHARMMParameterFile exist for that molecule, returning True if all parameters are present, otherwise False

classmethod from_file(prm_path: str)

Instantiate the class from a CHARMM PRM file.

Parameters

prm_path – path to the .prm/.str file.

get_unmatched(molecule) → Dict[str, Set[Tuple[str]]]

Check a finalized Molecule to verify that all the parameters in the CHARMMParameterFile exist for that molecule, returning necessary parameters which are missing.

Parameters

molecule – the Molecule

Returns

dict of parameter type (i.e. ‘bonds’/’angles’) to a set of tuples containing unmatched atom_type tuples.

read_file(prm_path: str) → None

Read in data from a CHARMM PRM file.

Parameters

prm_path – path to .prm/.str file

class pygen_structures.charmm_containers.CHARMMPatchResidueDefinition(name: str = 'Unset', atoms: (<class 'list'>, None) = None, bonds: (<class 'list'>, None) = None, impropers: (<class 'list'>, None) = None, cross_maps: (<class 'list'>, None) = None, ics: (<class 'list'>, None) = None, rtf_file_name: (<class 'str'>, None) = None, deletions: (<class 'set'>, None) = None, n_residues: int = 1)

Bases: pygen_structures.charmm_containers.CHARMMResidueData

Definition of a CHARMM patch residue. As CHARMM patches can apply to multiple residues, these are more complicated to represent than the residues they are applied to.

atoms, bonds, impropers, cross_maps and ics are n_residues long lists of the atoms, bonds, impropers, cross_maps and ics for each residue. This enables these to be zipped together with the actual residues the patch is to apply them to.

Atoms, due to their simplicity, are kept as the form they are stored in the residue: - (atom_name, atom_type, charge)

In the other representations, atoms are stored as atom references. These are tuples of (residue_index: int, atom_name: str), where residue_index is a placeholder for the order given in the patch. - e.g. 2SG1 -> (1, 'SG1') - “BOND 1SG1 2SG1” -> ((0, 'SG1'), (1, 'SG1'))

This is to account for new bonds/impropers/crossmaps/ics which involve atoms in different residues.

Parameters
  • name – patch name, from PRES record

  • atoms – an n_residues long list of lists containing (atom_name, atom_type, partial_charge)

  • bonds – an n_residues long list of lists containing tuples of 2 atom references, from BOND/DOUB records. Bonds in DOUB records appear twice.

  • impropers – an n_residues long list of lists containing tuples of 4 atom references from IMPR records

  • cross_maps – an n_residues long list of lists containing tuples of 8 atom references from CMAP records

  • ics – an n_residues long list of lists containing lists of information present in IC records. The first 4 items are atom references, the last 5 are floats containing bond and angle information. Where angle i-j-k-l is an improper, the third atom name is prefaced with “*”. The floats are: the bond length, i-j the angle, i-j-k the dihedral (or improper) i-j-k-l the angle j-k-l the bond length k-l

  • deletions – set of atom names which are to be deleted from the residue

apply(*residues)

Applies the CHARMM patch to an actual residue (or collection of actual residues).

Atoms to be deleted are removed from the applicable residues, with now-dangling bonds/impropers/cross-maps/ICs to these residues also removed.

New atoms, bonds, impropers, cross_maps and ics are then appended to the relevant residue.

Bonds are added to the residue which contains the first atom, all other multi-atom data is added to the residue which contains the second atom. This is to account for the fact that the other connections can feature atoms in the residue before and after in the first and last positions - in bonds, these tend do be in the first position.

classmethod from_block(block: str)

Generate the class from a PRES block in an RTF file. This is probably the most useful constructor.

Parameters

block – a multi-line string containing the PRES block.

Returns

An instance of the class

is_applicable_to(residue) → Union[None, List[int]]

Work out the positions where the patch can be applied to the residue. If the patch can be applied, return a list of positions where the patch can be applied, otherwise return None.

Parameters

residue – The CHARMMResidue the patch is to be applied to

Returns

A list of indices where the residue could be supplied to the patch, if applicable. Otherwise None.

class pygen_structures.charmm_containers.CHARMMResidue(name: str = 'Unset', atoms: (<class 'list'>, None) = None, bonds: (<class 'list'>, None) = None, impropers: (<class 'list'>, None) = None, cross_maps: (<class 'list'>, None) = None, ics: (<class 'list'>, None) = None, rtf_file_name: (<class 'str'>, None) = None, first: (<class 'str'>, None) = None, last: (<class 'str'>, None) = None, index: int = 0)

Bases: pygen_structures.charmm_containers.CHARMMResidueData

An actual CHARMM residue, in a molecule. This has an associated index. The atoms are unchanged from the residue definition (see CHARMMResidueDefinition), but rather than referring to atom_name, the bonds, impropers, cross_maps and ics now refer to atom_ids, which are unique atoms rather than general abstract atoms definitions.

An atom_id takes the following form:
  • (residue_index: int, atom_name: str)

Parameters
  • first – default patch if residue is first in chain. If None, this defaults to the default first patch of the CHARMMResidueTopologyFile the residue definition is in.

  • last – default patch if residue is last in the chain. Treated much the same way as first.

  • index – the residue_index.

classmethod from_residue_definition(residue_definition: pygen_structures.charmm_containers.CHARMMResidueDefinition, index: int, last_index: (<class 'int'>, None) = None, next_index: (<class 'int'>, None) = None)

Generate a CHARMMResidue from the residue definition. This is probably the most useful constructor.

Parameters
  • residue_definitionCHARMMResidueDefinition to clone.

  • index – the residue_index of the created residue.

  • last_index – the residue_index of the previous residue in the chain. Used for connections where atoms start with ‘-‘. Default: index - 1

  • last_index – the residue_index of the next residue in the chain. Used for connections where atoms start with ‘+’. Default: index - 1

Returns

the created residue.

class pygen_structures.charmm_containers.CHARMMResidueData(name: str = 'Unset', atoms: (<class 'list'>, None) = None, bonds: (<class 'list'>, None) = None, impropers: (<class 'list'>, None) = None, cross_maps: (<class 'list'>, None) = None, ics: (<class 'list'>, None) = None, rtf_file_name: (<class 'str'>, None) = None)

Bases: object

Base class for CHARMM residue data. Holds information present in a residue topology file (RTF) section.

class pygen_structures.charmm_containers.CHARMMResidueDefinition(name: str = 'Unset', atoms: (<class 'list'>, None) = None, bonds: (<class 'list'>, None) = None, impropers: (<class 'list'>, None) = None, cross_maps: (<class 'list'>, None) = None, ics: (<class 'list'>, None) = None, rtf_file_name: (<class 'str'>, None) = None, first: (<class 'str'>, None) = None, last: (<class 'str'>, None) = None)

Bases: pygen_structures.charmm_containers.CHARMMResidueData

Definition of a CHARMM residue. This is a general representation, and doesn’t have an associated index.

Parameters
  • name – residue name, from RESI record

  • atoms – list of (atom_name, atom_type, partial_charge), from ATOM records

  • bonds – lists of tuples of 2 atom_name, from BOND/DOUB records. Bonds in DOUB records appear twice.

  • impropers – lists of tuples of 4 atom_name from IMPR records

  • cross_maps – lists of tuples of 8 atom_name from CMAP records

  • ics – list of information present in IC records. The first 4 items are atom_name, the last 5 are floats containing bond length/angle information. Where angle i-j-k-l is an improper, the third atom_name is prefaced with “*”. The floats are: the bond length, i-j the angle, i-j-k the dihedral (or improper) i-j-k-l the angle j-k-l the bond length k-l

  • first – default patch if residue is first in the chain. If None, this defaults to the default first patch of the CHARMMResidueTopologyFile this residue definition is in.

  • last – default patch if residue is last in the chain. Treated much the same way as first.

classmethod from_block(block: str)

Generate the class from a RESI block in an RTF file. This is probably the most useful constructor.

Parameters

block – a multiline string containing the RESI block.

Returns

an instance of the class

to_fragment_mol() → rdkit.Chem.rdchem.RWMol

Generate a Structure and return the RDKit ``Mol generated. :return: RDKit RWMol

to_residue(index: int, last_index: (<class 'int'>, None) = None, next_index: (<class 'int'>, None) = None)

Generate a CHARMMResidue from the residue definition.

Parameters
  • index – the residue_index of the created residue.

  • last_index – the residue_index of the previous residue.

  • index – the residue_index of the next residue.

Returns

the created residue

Return type

CHARMMResidue

to_smarts()

Generate a Structure, grab the RDKit Mol, and call MolToSMARTS after removing hydrogen atoms.

Returns

the SMARTS string.

to_structure() → pygen_structures.mol_containers.structure.Structure

Returns the residue as a Structure object. These can be used for pattern matching of residues.

Returns

the generated Structure

class pygen_structures.charmm_containers.CHARMMResidueTopologyFile(file_name: (<class 'str'>, None) = None, residues: (<class 'dict'>, None) = None, patches: (<class 'dict'>, None) = None, masses: (<class 'dict'>, None) = None, first: (<class 'str'>, None) = None, last: (<class 'str'>, None) = None)

Bases: object

A class which reads and stores patch residues and residues from a CHARMM RTF or STR file.

Parameters
  • file_name – the name of the RTF file.

  • residues – a mapping of residue names to the CHARMMResidueDefinition which represents them.

  • patches – a mapping of patch residue names to the CHARMMPatchResidueDefinition which represents them.

  • masses – a mapping of atom_type to mass.

  • first – the name of the patch applied to the first residue in a chain.

  • last – the name of the patch applied to the last residue in a chain.

add_patch_definition(patch: pygen_structures.charmm_containers.CHARMMPatchResidueDefinition) → None

Add a CHARMMPatchResidueDefinition to the patches

Parameters

patch – a CHARMMPatchResidueDefinition

add_residue_definition(residue: pygen_structures.charmm_containers.CHARMMResidueDefinition) → None

Add a CHARMMResidueDefinition to the residues

Parameters

residue – a CHARMMResidueDefinition

classmethod from_file(rtf_path: str)

Instantiate the class from a CHARMM RTF file.

Parameters

rtf_path – path to .rtf/.str file

read_file(rtf_path: str, update_default_patches=False) → None

Read in a CHARMM RTF (or STR) file and add the patches and residues, updating the default patches if requested.

Parameters
  • rtf_path – path to the .rtf/.str file

  • update_default_patches – bool flag, updates first and last if True.