schrodinger.structure module¶
- schrodinger.structure.update_once()¶
A context manager to enable manual update mode to update the structure by calling update only once before exiting , and then restores the original manual update state.
- class schrodinger.structure.BondType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
enum.Enum
These represent varying bond types, which are independent from bond orders.
- Zero = 0¶
- Dative = 1¶
- Single = 2¶
- Double = 3¶
- Triple = 4¶
- class schrodinger.structure.UndefinedStereochemistry¶
Bases:
Exception
Raised by SmilesStructure.getStructure() when atoms with undefined chirality are present.
- class schrodinger.structure.AtomsInRingError¶
Bases:
ValueError
Raised by Structure.adjust() when atoms are in a ring, so adjustment can’t be made without distorting the structure.
- class schrodinger.structure._NotSortable¶
Bases:
object
Mix-in for classes that shouldn’t be sortable or orderable.
- class schrodinger.structure._AtomCollection(st, atoms)¶
Bases:
object
A set of atoms, usually comprising a subset of the total atoms in a Structure. Initialize using a structure and an iterable of current atom indices.
Important methods include
extractStructure
andgetAtomIndices
. Use theatom
attribute to iterate over all contained atoms. 1-based indexed access to the atoms is also possible usingatom
(e.g. atom[1] gets the first atom in the _AtomCollection). The number of atoms can be determined vialen(self.atom)
orlen(self)
.Intended as a base class for _Ring, _Molecule, and _Chain.
- __init__(st, atoms)¶
- property structure¶
Return the parent Structure object for this atom collection.
- property atom¶
Iterate over all atoms. Also allows 1-based indexed access to the atoms.
- __len__()¶
Return number of atoms.
- getAtomIndices()¶
Return a list of atom indices for all atoms in this object.
- Returns
List of atom indicies.
- Return type
list of ints
- getAtomList()¶
Deprecated. Use getAtomIndices() method instead.
- extractStructure(copy_props=False)¶
Return a new Structure containing only the atoms associated with this substructure. Structure properties, including the title, are inherited only if copy_props is set to True.
- property temperature_factor¶
Average B (temperature) factor for all atoms that have it assigned. Setting this property will set the B factor to the given value for each atom.
- class schrodinger.structure._Ring(st, ringnum, atoms, iterator)¶
Bases:
schrodinger.structure._structure._AtomCollection
Class representing a ring.
Important methods include
extractStructure
andgetAtomIndices
. Theatom
attribute returns an iterator over all atoms in the ring, and the number of atoms can be determined vialen(molecule.atom)
. Theedge
attribute works in a similar manner for bonds in the ring.- __init__(st, ringnum, atoms, iterator)¶
- property edge¶
Returns a bond iterator for all edges in the ring.
- isAromatic()¶
- isHeteroaromatic()¶
- applyStyle(atoms=3, bonds=3)¶
Applies the given display styles to the atoms and bonds of the ring.
- Parameters
atoms (int) – display style for atoms given by structure module constants ATOM_NOSTYLE, ATOM_CIRCLE, ATOM_CPK, ATOM_BALLNSTICK. Default is ATOM_BALLNSTICK.
atoms – display style for bonds given by structure module constants BOND_NOSTYLE, BOND_WIRE, BOND_TUBE, BOND_BALLNSTICK. Default is BOND_BALLNSTICK.
- class schrodinger.structure._Molecule(st, molnum, atoms)¶
Bases:
schrodinger.structure._structure._AtomCollection
A class used to return molecule information when iterating over molecules in a Structure object.
Important methods include
extractStructure
andgetAtomIndices
. Theatom
attribute can be used to iterate over all atoms in the molecule, and the number of atoms can be determined vialen(molecule.atom)
.The
residue
iterator allows for iteration over residues of the molecule, returning_Residue
instances.- __init__(st, molnum, atoms)¶
Initialize the Molecule object.
- property residue¶
Returns residue iterator for all residues in the molecule.
- property number¶
Returns the molecule number of this molecule.
- property number_by_entry¶
Return molecule number of this molecule by entry.
- applyStyle(atoms=3, bonds=3)¶
Applies the given display styles to the atoms and bonds of the molecule.
- Parameters
atoms (int) – display style for atoms given by structure module constants ATOM_NOSTYLE, ATOM_CIRCLE, ATOM_CPK, ATOM_BALLNSTICK. Default is ATOM_BALLNSTICK.
atoms – display style for bonds given by structure module constants BOND_NOSTYLE, BOND_WIRE, BOND_TUBE, BOND_BALLNSTICK. Default is BOND_BALLNSTICK.
- class schrodinger.structure.Residue(st, resnum, inscode, chain, atoms=[])¶
Bases:
schrodinger.structure._structure._AtomCollection
A class which is returned by the ResidueIterator and contains information about the residue including the atoms which make it up.
Important methods include
extractStructure
andgetAtomIndices
. Theatom
attribute can be used to iterate over all atoms in the molecule, and the number of atoms can be determined vialen(molecule.atom)
.- __init__(st, resnum, inscode, chain, atoms=[])¶
- property pdbres¶
Returns PDB residue name.
- property chain¶
Return chain name.
- property resnum¶
Returns PDB residue number.
- property inscode¶
Returns PDB residue insertion code.
- property molecule_number¶
Return molecule number.
- property molecule_number_by_entry¶
Return molecule number of this residue by entry.
- property secondary_structure¶
- getCode()¶
Return the one-letter residue code for this residue.
- hasMissingAtoms()¶
Returns True is this residue doesn’t have the expected number of heavy atoms. Will return False is this residue has the correct number of heavy atoms or if it is of a type we don’t know
- isStandardResidue()¶
Returns True if this residue is on the list of standard PDB residues
- isConnectedToResidue(other_res)¶
Returns True if the given residue is connected (C->N) to this residue.
If the “C” PDB atom of this residue is connected to the “N” PDB atom of the other_res, then the residues are connected. Otherwise, they are not considered connected.
- applyStyle(atoms=3, bonds=3)¶
Applies the given display styles to the atoms and bonds of the residue.
- Parameters
atoms (int) – display style for atoms given by structure module constants ATOM_NOSTYLE, ATOM_CIRCLE, ATOM_CPK, ATOM_BALLNSTICK. Default is ATOM_BALLNSTICK.
atoms – display style for bonds given by structure module constants BOND_NOSTYLE, BOND_WIRE, BOND_TUBE, BOND_BALLNSTICK. Default is BOND_BALLNSTICK.
- getAtomByPdbName(pdbname)¶
Returns the atom of this residue that matches the given PDB name, or None if no such atom is found.
- Parameters
pdbname (str) – 4-letter PDB atom name. E.g. ” C ” to get the C terminal atom of a protein residue.
- Returns
Atom with given PDB name or None
- Return type
StructureAtom
or None
- getBackboneNitrogen()¶
Returns the backbone nitrogen of the residue, or None. NOTE: For use with protein residues only.
- Returns
Nitrogen atom or None
- Return type
StructureAtom
or None
- getCarbonylCarbon()¶
Returns the carbonyl backbone carbon of the residue, or None. NOTE: For use with protein residues only.
- Returns
Carbon atom or None
- Return type
StructureAtom
or None
- getBackboneOxygen()¶
Returns the oxygen of the backbone, or None. NOTE: For use with protein residues only.
- Returns
Oxygen atom or None
- Return type
StructureAtom
or None
- getAlphaCarbon()¶
Returns the backbone alpha carbon atom of this residue, or None. NOTE: For use with protein residues only.
- Returns
Alpha carbon atom or None
- Return type
StructureAtom
or None
- getBetaCarbon(gly_hydrogen=False)¶
Returns the beta carbon atom of this residue, or None. NOTE: For use with protein residues only.
- Parameters
gly_hydrogen (bool) – Whether to return the hydrogen atom if the residue is a glycine.
- Returns
Beta carbon atom or None
- Return type
StructureAtom
or None
- getDihedralAtoms(angle_name)¶
Return a list of 4 atom objects for the named dihedral angle in this residue. For backbone bonds, atoms are listed in the N->C order; for side-chain bonds, atoms are listed in order of increasing bond count from the backbone. Omega dihedral is the one to the previous residue (the one bonded to the N atom of this residue).
- Parameters
name (str) – Name of the dihedral angle to fine. Supported names are: Phi, Psi, Omega, Chi1, Chi2, Chi3, Chi4, Chi5.
- Raises
ValueError – if specified dihedral name is not valid or if it was not found in the database.
- getAsl()¶
Return an ASL that uniquely identifies this residue, by chain ID, residue number, and insertion code.
- class schrodinger.structure._Chain(st, chain, atoms)¶
Bases:
schrodinger.structure._structure._AtomCollection
A class used to return chain information when iterating over chains in a Structure object.
Important methods include
extractStructure
andgetAtomIndices
. Theatom
attribute can be used to iterate over all atoms in the molecule, and the number of atoms can be determined vialen(molecule.atom)
.The
residue
iterator allows for iteration over residues of the chain, returning_Residue
instances.- __init__(st, chain, atoms)¶
Initialize the Chain object.
- property residue¶
Returns residue iterator for all residues in the chain
- property name¶
Return name of the chain.
- applyStyle(atoms=3, bonds=3)¶
Applies the given display styles to the atoms and bonds of the chain.
- Parameters
atoms (int) – display style for atoms given by structure module constants ATOM_NOSTYLE, ATOM_CIRCLE, ATOM_CPK, ATOM_BALLNSTICK. Default is ATOM_BALLNSTICK.
atoms – display style for bonds given by structure module constants BOND_NOSTYLE, BOND_WIRE, BOND_TUBE, BOND_BALLNSTICK. Default is BOND_BALLNSTICK.
- class schrodinger.structure._StructureAtomProperty(ct, cpp_atom)¶
Bases:
collections.abc.MutableMapping
Dictionary-like container of atom based properties. These can be accessed via the property name as it appears in the maestro file.
Property names must be m2io data names, which are in the format ‘<type>_<author>_<property_name>’, where ‘<type>’ is a data type prefix, ‘<author>’ is a source specification, and ‘<property_name>’ is the actual name of the data.
The data type prefix can specified as ‘s’ for string, ‘i’ for integer, ‘r’ for real and ‘b’ for boolean. The author specification should be ‘user’ for user created properties. The property name can have embedded underscores.
Some example m2io datanames are ‘r_m_x_coord’, which indicates a real maestro property named ‘x coord’, and ‘i_user_my_count’ which indicates an integer user property named ‘my count’.
- __init__(ct, cpp_atom)¶
Create an instance of the property dictionary.
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- keys()¶
Returns a list of the datanames of all unrequested items.
- clear()¶
Clear all properties (except the built-in ones).
- __len__()¶
- class schrodinger.structure.StructureAtom(ct, cpp_atom)¶
Bases:
schrodinger.structure._structure._NotSortable
Access of mmct atoms properties pythonically.
Note that this class is not intended to be instantiated directly.
- __init__(ct, cpp_atom)¶
Create an instance from the Structure object and the atom index. Note that the index used starts at 1 as per the underlying mmct lib.
Note that this class is not intended to be instantiated directly.
- property index¶
- addBond(atom2, bond_order)¶
Add a bond between the current atom and atom2. :param bond_order Takes an integer bond order or a BondType
- deleteBond(atom2)¶
Delete the bond between the current atom and atom2.
- retype()¶
Reassign the MacroModel atom type based on the bond orders and formal charge. This function should be called after either of these have been changed.
- getResidue()¶
Return a _Residue object for the residue that this atom is part of.
- getMolecule()¶
Return a _Molecule object for the molecule that this atom is part of.
- getChain()¶
Return a _Chain object for the molecule that this atom is part of.
- property structure¶
Return the parent Structure object for this atom.
- property bond_total¶
Get total number of bonds to this atom.
- property bond¶
List of bonds to the atom (
_StructureBond
objects).
- property bonded_atoms¶
Iterator for atoms bonded to this atom (
StructureAtom
objects).
- property atomic_weight¶
Return the atomic weight of the atom.
If implicit hydrogens are present, these are included with the weight of the atom they are attached to.
- property growname¶
Returns Maestro grow name.
- property pdbname¶
Returns PDB atom name.
- property pdbres¶
- property pdbcode¶
Returns one-letter PDB residue code.
- property resnum¶
Returns PDB residue number.
- property inscode¶
Returns PDB residue insertion code.
- property atom_type¶
- property atom_type_name¶
Returns MacroModel atom type name.
- property color¶
Get property method for StructureAtom.color attribute.
:return Color object. :rtype:
color.Color
- setColorRGB(red, green, blue)¶
Set the RGB color of this atom as a tuple (R,G.B). Each color value should be an integer between 0 and 255.
- property chain¶
Chain name (mmCIF “auth_asym_id”)
- property chain_name¶
Chain name (mmCIF “auth_asym_id”).
This property is deprecated, please use chain instead.
- property atom_name¶
- property name¶
Return name of atom.
- property entry_id¶
Return maestro entry id, may be None.
- property element¶
Element symbol of the atom.
- property partial_charge¶
Return partial charge of the atom.
- property solvation_charge¶
- property formal_charge¶
- property isotope¶
Returns mass number charge of the atom.
- property secondary_structure¶
- property temperature_factor¶
- property radius¶
- property vdw_radius¶
- property is_halogen¶
- property molecule_number¶
- property molecule_number_by_entry¶
Return the molecule number of this atom, by entry.
- property number_by_molecule¶
- property number_by_entry¶
- property atomic_number¶
“Atomic number of the atom’s element.
- property x¶
- property y¶
- property z¶
- property xyz¶
XYZ-coordinates of the atom.
- property alt_xyz¶
Alternative XYZ-coordinates of the atom, if available, otherwise returns None.
- property chirality¶
Returns chirality of the atom. R, S, ANR, ANS, undef, or None.
- property atom_style¶
- property style¶
- property visible¶
- property label_format¶
- property label_color¶
- property label_user_text¶
- property property¶
Dictionary-like container of Atom-level properties. Keys are strings of the form
type_family_name
as described in the “PropertyName
documentation.
- class schrodinger.structure._StructureBondProperty(ct, atomindex, bondnum)¶
Bases:
collections.abc.MutableMapping
Dictionary-like container of bond based properties. These can be accessed via the property name as it appears in the maestro file.
Property names must be m2io data names, which are in the format ‘<type>_<author>_<property_name>’, where ‘<type>’ is a data type prefix, ‘<author>’ is a source specification, and ‘<property_name>’ is the actual name of the data.
The data type prefix can specified as ‘s’ for string, ‘i’ for integer, ‘r’ for real and ‘b’ for boolean. The author specification should be ‘user’ for user created properties. The property name can have embedded underscores.
Some example m2io datanames are ‘r_m_x_coord’, which indicates a real maestro property named ‘x coord’, and ‘i_user_my_count’ which indicates an integer user property named ‘my count’.
- __init__(ct, atomindex, bondnum)¶
Create an instance of the property dictionary.
- keys()¶
Returns a list of the datanames of all unrequested items.
- __len__()¶
- class schrodinger.structure.StructureBond(ct, atom_index, index)¶
Bases:
schrodinger.structure._structure._NotSortable
A class for pythonic access to bond properties.
- Attributes
atom1: The first atom, by which the bond is defined.
atom2: The atom bonded to atom1.
- __init__(ct, atom_index, index)¶
A bond is defined by its underlying Structure, the atom index that it is anchored to, and the bond index.
- delete()¶
Delete this bond. Use with care. Iteration over bonds may be affected.
- property length¶
Length of the bond in angstroms.
- property order¶
Return bond order. Returns None for the MMCT_NONE type, integer values for zero through three.
- property type¶
:returns schrodinger.structure.BondType
- property from_style¶
Return bond’s “from” style.
- property to_style¶
Return bond’s “to” style.
- property style¶
- setStyle(style)¶
Set the bond’s style in both directions (“from” and “to”)
- property atom¶
Returns an iterable of the atoms and can also be used for easy inclusion checks
- property property¶
Dictionary-like container of Bond properties.
- otherAtom(atom)¶
Given one atom in the bond, return the other atom in the bond,
- Parameters
atom (StructureAtom or int) – atom object or its index which is one side of the bond
- Return type
- Returns
the atom in the bond that is not the input atom
- class schrodinger.structure._StructureAtomContainer(st)¶
Bases:
object
The class to provide access to StructureAtom instances.
- __init__(st)¶
Initialize the container. The underlying mmct is always present.
- __len__()¶
Return the number of atoms by querying the Structure class.
- class schrodinger.structure._StructureBondContainer(ct)¶
Bases:
object
The class to provide access to _StructureBond instances for each bond in the structure.
- __init__(ct)¶
Initialize with a Structure.
- static bond_iter(st)¶
Low level iterator over all bonds.
- Parameters
st (structure.Structure) – Structure to use
- Return type
int, int, int
- Returns
Index of bonded atom1, index of bonded atom2, bond index
- __len__()¶
Return the total number of bonds in the Structure
- class schrodinger.structure._AtomBondContainer(ct, atom_index)¶
Bases:
object
The class to provide access to _StructureBond instances for each bond of an atom.
- __init__(ct, atom_index)¶
Initialize with a Structure and an atom index.
- __len__()¶
Return the number of bonds by querying the Structure class.
- class schrodinger.structure._StructureProperty(st, read_only=False)¶
Bases:
collections.abc.MutableMapping
Dictionary-like container of Structure based properties, with all dict methods. Properties can be accessed via the m2io dataname as it appears in the maestro file.
Property names must be m2io data names, which are in the format ‘<type>_<author>_<property_name>’, where ‘<type>’ is a data type prefix, ‘<author>’ is a source specification, and ‘<property_name>’ is the actual name of the data.
The data type prefix can specified as ‘s’ for string, ‘i’ for integer, ‘r’ for real and ‘b’ for boolean. The author specification should be ‘user’ for user created properties. The property name can have embedded underscores.
Some example m2io datanames are ‘r_m_x_coord’, which indicates a real maestro property named ‘x coord’, and ‘i_user_my_count’ which indicates an integer user property named ‘my count’.
- To convert to the _StructureProperty to a real dictionary::
d = dict(st.property)
- To set all properties from dictionary::
st.property = {…}
- __init__(st, read_only=False)¶
Create an instance of the property ‘dictionary’ The instance is created when st.property is first used. If read-only is True then only read-access will be supported.
- keys()¶
Return a list of the names of all properties.
- clear()¶
Clear all properties (except the title).
- __len__()¶
- class schrodinger.structure.Structure(handle, *, take_ownership=True)¶
Bases:
object
A general chemical structure object, which may contain multiple molecules. Structure is an object-oriented wrapper for the underlying MMCT library, where all state is stored.
There are several ways to create Structure instances. The structure.StructureReader provides a way to read Structures from a file, and the
schrodinger.maestro.maestro.workspace_get
function returns the workspace Structure from a Maestro session. Theschrodinger.project
module provides access to Structures in a Maestro project.Properties of the Structure entry can be accessed from the
property
dictionary using themae
file data name. For example, the Glide score of a docked pose may be accessed as:glide_score = st.property['r_i_glide_gscore']
A few additional Structure attributes are available as instance attributes (actually, as python properties). For example, the title of the structure can be accessed (and assigned) via the
title
attribute. See the Structure properties documentation for a full list.Atom objects are accessed from the list-like
schrodinger.structure.Structure.atom
attribute. Each atom is an instance of theStructureAtom
class. See the “Properties” section of theschrodinger.structure.StructureAtom
documentation for a list of available attributes (implemented again as python properties). For example, the atomic number of the first atom in a structure is accessed as:atomic_num = st.atom[1].atomic_number
Note that indices used to access atoms and bonds start at 1, not 0 as with regular python lists. Iteration over the atoms and bonds works as expected.
Structure atom properties may also be accessed from the atom’s
property
dictionary. For example, the x-coordinate of the first atom may be accessed as:x_coord = st.atom[1].property['r_m_x_coord']
(However, it is preferable to simply use the
x
attribute - i.e.st.atom[1].x
.)Bond objects are instances of the
schrodinger.structure._StructureBond
class and are usually accessed via atoms using theschrodinger.structure.StructureAtom.bond
attribute. Like atoms, bonds have some built-in attributes and a generalproperty
dictionary. Bonds can also be accessed from theschrodinger.structure.Structure.bond
iterator, which iterates over all bonds in the Structure.Iterators for various substructures can be accessed from the
molecule
,chain
,residue
, andring
attributes. Each of these yields an object that has agetAtomIndices
method to get a list of atom indices, and anextractStructure
method that can be used to create a separateStructure
instance corresponding to the substructure.Please see the Python Module Overview for a non-technical introduction and additional examples.
- __init__(handle, *, take_ownership=True)¶
Initialize an object with an existing MMCT handle or a C++ Structure object.
- copy()¶
Returns a copy of the structure.
- getXYZ(copy=True)¶
Get a numpy array of the xyz coordinates of all atoms in the molecule with shape (atom_total, 3). Note that numpy arrays are indexed starting with 0.
You can avoid copying the underlying data by specifying copy=False, in which case modifying any values will modify the coordinate values in the Structure.
Note that if coordinates are retrieved with copy=False they will become invalid after their source Structure has been garbage collected. Any use of them after this point will likely cause a core dump. This is because the python numpy array provides access directly to the underlying C data.
- setXYZ(xyz)¶
Set all xyz coordinates for the molecule from a numpy array.
- findResidue(query)¶
Returns a
_Residue
object matching the given string (e.g. “A:123”). Currently only protein residues are supported.If no residues were found that match the given string, or if the given string is of improper format, ValueError is raised.
- Note
If the structure has more than one matching residue, then only the first match will be returned.
- atom¶
An iterable of structure atoms, each of which is a
StructureAtom
instance.Example usage, where
st
is a Structure instance:# Access an atom (indices start at 1) atomobj = st.atom[n] # Delete an atom del st.atom[n] # Find the number of atoms len(st.atom) # Iterate over all atoms for atom in st.atom: take_some_action(atom)
- Note
As with many other collections, the contents of the atom list should not be modified through additions or deletions while you are iterating over it.
- bond¶
An iterable of structure bonds, each of which is a
_StructureBond
instance.To iterate over bonds:
for bond in st.bond: take_some_action(bond)
- Note
Atoms and bonds should not be added or deleted while you are iterating over bonds.
- Note
Bonds are not accessible by index.
- molecule¶
An iterable of molecules in the structure, each of which is a
_Molecule
instance.Example usage:
# Find the number of molecules in the structure len(st.molecule) # Retrieve a molecule by number (indices start at 1) mol = st.molecule[molnum] # Iterate over all molecules for mol in st.molecule: take_some_action(mol)
- Note
Atoms and bonds should not be added or deleted while you are iterating over molecules.
- chain¶
An iterable of chains in the structure, each of which is a
_Chain
instance.Example usage:
# Find the number of chains in the structure len(st.chain) # Retrieve a _Chain instance by letter chain = st.chain[letter] # Iterate over chains for chain in st.chain: take_some_action(chain)
- Note
Atoms and bonds should not be added or deleted while you are iterating over chains.
- ring¶
An iterable of rings in the structure, each of which is a
_Ring
instance.To iterate over rings:
for ring in st.ring: take_some_action(ring)
- Note
Atoms and bonds should not be added or deleted while you are iterating over rings.
- property title¶
Get the title for this structure
- property atom_total¶
Get total number of atoms in this structure
- property mol_total¶
Get total number of molecules in this structure
- property formal_charge¶
Get the sum of formal charges for the structure.
- property total_weight¶
The sum of atomic weights for the whole structure.
The weight of implicit hydrogens is automatically included.
Accessing this property is an O(N) operation.
- property residue¶
An iterable of residues in the structure, each of which is a
_Residue
instance.To iterate over all residues:
for residue in st.residue: take_some_action(residue)
- Note
Atoms and bonds should not be added or deleted while you are iterating over residues.
- Note
residues are not accessible by index. See
Structure.findResidue()
- property pbc¶
Access the PBC of the Structure. Throws KeyError if no PBC exists
- property property¶
Dictionary-like container of Structure-level properties. Keys are strings of the form
type_family_name
as described in thePropertyName
documentation.
- retype()¶
Reassign all the MacroModel atom types based on the bond orders and formal charges. This function should be called after either of these have been changed.
- static read(filename, index=1)¶
Convenience method for the preferred call to StructureReader.read()
- writeToString(format)¶
Write the structure to a string representation and return the string. The format parameter is required.
- write(filename, format=None)¶
Convenience method for the preferred call to StructureWriter.write()
- append(filename, format=None)¶
Convenience method for the preferred StructureWriter context manager
- putToM2ioFile(filehandle)¶
Used by the Maestro writer - put a single structure to the (already open) filehandle
- closeBlockIfNecessary(filehandle)¶
Used by the Maestro writer to leave the header block if necessary. For Structure objects this is not needed so it only returns
- deleteAtoms(indices, renumber_map=False)¶
Delete multiple atoms from the Structure. The argument indices must be a sequence or an iterable, and able to be interpreted as ints.
After deletion, indices are renumbered from 1 to len(atoms). Pre-existing references to Structure atoms will not be correct, as they store index values.
If renumber_map is set to True, will return a renumbering dictionary. Keys are atom numbers before deleting, and value for each is the new atom number, or None if that atom was deleted.
- addAtom(element, x, y, z, color=None, atom_type=None)¶
Add a new atom to the structure. Return the created
StructureAtom
object.
- addAtoms(num_atoms)¶
Add the specified number of atoms to this structure.
The following atom attributes will have to be set for each atom afterwards:
element
x
,y
,z
color
atom_type
- extract(indices, copy_props=False)¶
Return a new structure object which contains the atoms of the current structure that appear in the specified list.
After extractions, indices are renumbered from 1 to len(atoms). Pre-existing references to Structure atoms will not be correct, as they store index values.
- Parameters
indices (iterable or sequence) – List of atom indices to extract
copy_props (bool) – Whether to copy structure properties
- Return type
- Returns
Extracted structure
- extend(other_structure)¶
Add the atoms in other_structure to the end of the current structure. The other_structure is left unchanged.
- Raises
ValueError – Extending a structure with itself is not allowed.
- merge(other_structure, copy_props=False)¶
Return a new structure object which contains the atoms of the current structure and the atoms of other_structure.
If copy_props is True, properties from the current structure and other_structure will be added to the new structure. If the same property is specifed in both the current structure and other_structure, the current value will take precedence.
- areBound(atom1, atom2)¶
Returns True if atom1 and atom2 have a bond of any order between them and False is there is no bond.
- getBond(atom1, atom2)¶
Returns a
_StructureBond
object for the bond between atom1 and atom2. The atom parameters can beStructureAtom
objects or integer indices from 1 to the number of atoms in the structure.
- addBond(atom1, atom2, bond_type)¶
Add a bond of the specified type between the two atoms atom1 and atom2. The atom parameters can be
StructureAtom
objects or integer indices from 1 to the number of atoms in the structure. If the two atoms are already bound then the bond type is just changed.:param bond_type bond type (legacy integer 0-3 bond order)
- addBonds(bonds_list)¶
Add multiple bonds to this structure. This is much faster than multiple calls to addBond() method when many bonds need to be added. Bonds are specified by a list of integer lists: (atom1, atom2, bond_type).
- Example::
st.addBonds([(10, 11, 1), (12, 13, 2)])
This will add a single-order bond between atoms 10 and 11, and a double-order bond between atoms 12 and 13.
- deleteBond(atom1, atom2)¶
Delete the bond between atom1 and atom2. Raises an Exception if there is no bond between these two.
- measure(atom1, atom2, atom3=None, atom4=None)¶
Return the measurement for the provided atoms. If atom3 is None, return the distance between atom1 and atom2. If atom4 is None, return the angle with atoms 1 through 3, and if all atoms are provided, return the dihedral angle.
All atom arguments can be integers or
StructureAtom
objects.If Periodic Boundary Condition CT-level properties are defined, uses the PBC measurement.
See also the structutil.measure module, which has functions to make measurements between atoms in different structures, and can also measure angles between planes.
- adjust(value, atom1, atom2, atom3=None, atom4=None)¶
Adjust a distance, angle or dihedral angle. If atom3 is None then the distance between atom1 and atom2 will be set to value, atom2 and all atoms attached to that atom will be moved. If atom4 is None then the angle between atom1, atom2 and atom3 will set to value, atom3 and all other atoms attached to that will be moved. If all atoms are specified then the dihedral angle made by atom1, atom2, atom3 and atom4 will be set to value and atom4 and all other atoms attached to that will be moved. All distances are specified in Angstroms, all angles in degrees.
NOTE: To adjust improper dihedrals, use build.adjustImproperDihedral instead
- Parameters
value (float) – value the internal coordinate will be set to
atom1 (int or StructureAtom) – first atom in the coordinate
atom2 (int or StructureAtom) – second atom in the coordinate
atom3 (int or StructureAtom or None) – third atom in the coordinate (if None, the coordinate is a bond)
atom4 (int or StructureAtom or None) – fourth atom in the coordinate (if None, the coordinate is an angle)
- Raises
AtomsInRingError – if specified atoms are within a ring system.
- getMovingAtoms(fixed_atom, moving_atom)¶
Returns all atoms that would move if <moving_atom> is moved while <fixed_atom> is frozen. This effectively returns all atoms in the same molecule substructure as <moving_atom> (atoms in the same substructure as fixed_atom are excluded).
In other words, if the bond between the moving_atom and fixed_atom (or towards the direction of fixed_atom) were to be broken, the atoms that would be in the same molecule as moving_atom are returned. Can be used for detecting things like residue side-chain atoms, etc.
- Note
If fixed_atom and moving_atom are part of different molecules, then all atoms in the moving_atom’s molecule will be returned. If fixed_atom and moving_atom are not bound directly, the intervening atoms will not be included in the result. If fixed_atom and moving_atom are connected with more than one path (are in a ring), then ValueError is raised.
- Parameters
fixed_atom (Atom index or
StructureAtom
.) – Atom which is part of the molecule that is to be excluded from the result (frozen, not being moved).moving_atom (Atom index or
StructureAtom
.) – Atom of interest (atom to be moved); a set of atoms that would be moved with it (connected to it) will be returned.
- Return type
Set of ints
- Returns
Set of atom indices for atoms “connected” to moving_atom - those atoms that would be moved with it if it was moved. For example, if called with alpha carbon and beta carbon atoms of a protein residue, then all side-chain atoms would be returned. Atom moving_atom will also be included.
Raises ValueError if the given atoms are part of a ring (in other words, moving_atom is connected to fixed_atom via more than one path). This may happen if part of the moving_atom’s “chain” is bonded to something unexpected; e.g. ZOBed to metals, or involved in a di-sulfide bond.
- getResidueAtoms(atom)¶
Return a list of atom objects that are in the same residue as ‘atom’.
- getMoleculeAtoms(atom)¶
Return a list of atom objects that are in the same molecule as ‘atom’.
- getChainAtoms(atom)¶
Return a list of atom objects that are in the same chain as ‘atom’.
- getAtomIndices()¶
Return a list of all atom indices in this structure.
- getPropertyNames()¶
- getAtomPropertyNames(include_builtin=False)¶
Return a tuple of atom-level property names present in this CT.
- Param
include_builtin: Whether to include built-in properties.
- hasAtomProperty(prop_name)¶
Return True if the structure has the property named prop_name, False otherwise
- Parameters
prop_name (str) – the name of the property
- deletePropertyFromAllAtoms(prop_name)¶
Deletes a property from all atoms present in structure
- Param
prop_name: The name of the atom-level property to delete.
- isEquivalent(struct, check_stereo=True)¶
Return True if the 2 structures are equivalent Return False if the 2 structures are different
struct: Another structure class object
check_stereo: Specifies whether or not to check stereo chemistry.
- find_rings(sort=True)¶
Find all rings in the structure using SSSR.
Each ring is returned in connectivity order.
- Parameters
sort (bool) – Deprecated and unused
- Returns
A list of lists of integers corresponding to the atom indices of the rings.
- applyTubeStyle(atom_list=None)¶
Applies CPK styles to the atoms and bonds of the entire structure (by default) or to the atoms (and their bonds) given in atom_list.
- Parameters
atom_list (iterable) – An iterable of atom objects or atom indices to apply the given styles to. If not included the styles are applied to all atoms in the structure.
- applyCPKStyle(atom_list=None)¶
Applies CPK styles to the atoms and bonds of the entire structure (by default) or to the atoms (and their bonds) given in atom_list.
- Parameters
atom_list (iterable) – An iterable of atom objects or atom indices to apply the given styles to. If not included the styles are applied to all atoms in the structure.
- applyWireStyle(atom_list=None)¶
Applies wire styles to the atoms and bonds of the entire structure (by default) or to the atoms (and their bonds) given in atom_list.
- Parameters
atom_list (iterable) – An iterable of atom objects or atom indices to apply the given styles to. If not included the styles are applied to all atoms in the structure.
- applyStyle(atoms=3, bonds=3, atom_list=None)¶
Applies the given display styles to the atoms and bonds of the entire structure (by default) or to the atoms (and their bonds) given in atom_list.
- Parameters
atoms (int) – Display style for atoms, given by structure module constants ATOM_NOSTYLE, ATOM_CIRCLE, ATOM_CPK, ATOM_BALLNSTICK. Default is ATOM_BALLNSTICK.
atoms – Display style for bonds, given by structure module constants BOND_NOSTYLE, BOND_WIRE, BOND_TUBE, BOND_BALLNSTICK. Default is BOND_BALLNSTICK.
atom_list (iterable) – An iterable of atom objects or atom indices to apply the given styles to. If not included the styles are applied to all atoms in the structure. Possible examples include:: [1, 3, 5] ring.atom schrodinger.structutils.analyze.evalulate_asl(asl_expr) [structure.atom[x] for x in xrange(50)] maestro.selected_atoms_get()
- has3dCoords()¶
Returns True if any atom in the structure has a non-zero z-coordinate.
- get3dStructure(require_stereo=True)¶
- Deprecated
Use generate3dConformation() instead.
- generate3dConformation(require_stereo=True)¶
Generate new 3D coordinates for the current structure, and add hydrogens if any are missing. This method is useful for “volumizing” a 2D structure into 3D. NOTE: For 2D inputs, annotation properties must be present for chiral centers to be processed correctly.
- Parameters
require_stereo (bool) – Whether to require all chiral centers to have defined stereochemistry via annotation properties. Defaults to True. UndefinedStereochemistry exception is raised if any chiral atom has ambiguous chirality. If set to False, ambiguous chiralities will be expanded arbitrarily.
- schrodinger.structure.write_ct_to_string(st)¶
Return a string representation of the provided Structure, formatted as a Maestro file.
- schrodinger.structure.write_ct_to_sd_string(st)¶
Return a string representation of the provided Structure, formatted as an SD file.
- class schrodinger.structure.PropertyName(dataname=None, type=None, family=None, username=None)¶
Bases:
object
The PropertyName class can be used to display the “user-readable” version of an entry or atom property to the user.
Properties are stored in
mae
files with names in the formtype_family_name
, wheretype
is a datatype indicator,family
indicates the owner or creator of the property, andname
is the name of the property. These strings are used as the keys in theproperty
dictionary attributes ofStructure
,StructureAtom
, and_StructureBond
. Examples includes_m_title
, which is a string created by Maestro with the name “title”, andi_m_residue_number
, which is an integer created by Maestro with the name “residue number”.- __init__(dataname=None, type=None, family=None, username=None)¶
The PropertyName constructor operates in one of two modes - either a dataname needs to be provided, or each of type, family, and username needs to be provided.
- Parameters
dataname (str) – The full property name, e.g. ‘s_m_title’.
type (enum) – The property value type, which must be ‘s’, ‘r’, ‘i’, or ‘b’. You can also use the predefined module constants
PROP_STRING
,PROP_FLOAT
(or equivalentlyPROP_REAL
),PROP_INTEGER
, andPROP_BOOLEAN
.family (str) – The family/owner of the property. If the family is one of the recognized long family names (e.g. ‘QikProp’ - see the keys of the
PROP_SHORT_NAME
dict), the short family name is assigned automatically.username (str) – The name a user would see displayed in the Maestro project table. Underscores are replaced with spaces unless protected by a backslash (in which case the backslash is not displayed). Internally, PropertyName will store the ‘name’, which is the fragment of the dataname that is not the type or family.
- dataName()¶
Returns the m2io data name of form
type_family_name
.This is the fully qualified name that includes the type, owner and name and should be used for all lookup, indexing, etc.
- userName()¶
Returns the user name of this property. User name is the shortened, user-readable name that should only be used when presenting this property to the user, such as in a GUI pull down menu.
Since data names can NOT have spaces in them, while user names can, we have a convention where a space in a user name is represented as an underscore in the data name, and an underscore in the user name has to be escaped with a backslash in the data name.
Replace ‘_’ with ‘_’, and ‘_’ with ‘ ‘ before returning the user name
- userNameWithFamily()¶
Returns the property name to be displayed in UI widgets, such as combo menus and tables. The display name is the “user” name, followed by the family in parentheses.
- Returns
Property name with family name in parentheses.
- Return type
str
- isFamily(family)¶
Checks if passed
family
parameter is valid.- Parameters
family (str) – The short name for family/owner of the property. Must be present in PROP_LONG_NAME.
- Raises
ValueError – If
family
key does not exist in PROP_LONG_NAME.
- schrodinger.structure.create_new_structure(num_atoms=0)¶
Returns a new Structure object.
If the Structure is created without atoms, they can be added with the
Structure.addAtom
orStructure.addAtoms
methods.Otherwise, the following atom attributes must be set for each atom afterwards:
element
x
,y
,z
color
atom_type
- Parameters
num_atoms – The number of atoms to create the structure with.
- schrodinger.structure.get_residues_by_connectivity(atom_container)¶
Access residues in N->C connectivity order
- Parameters
atom_container (
Structure._Chain
,Structure._Structure
, orStructure._Molecule
) – Anything with an atom() method that returns atom indexes- Returns
A residue iterator where the atoms are returned in N->C connectivity order
- Return type
Structure._ResidueIterable
- schrodinger.structure.get_residues_unsorted(atom_container)¶
Access residues in the unsorted input order
- Parameters
atom_container (
Structure._Chain
,Structure._Structure
, orStructure._Molecule
) – Anything with an atom() method that returns atom indexes- Returns
A residue iterator where the atoms are returned in unsorted order
- Return type
Structure._ResidueIterable
- schrodinger.structure.get_pyatom_from_cppatom(cppatom)¶
Given a C++ atom object, return the corresponding Python atom.
- Parameters
cppatom (
schrodinger.infra.structure.StructureAtom
) – C++ atom object- Returns
The corresponding Python atom object
- Return type
structure.StructureAtom
- schrodinger.structure.set_all_atoms_entry_id_from_entry_id_property(st)¶
Set entry id property from the structure’s M2IO_DATA_CT_ENTRY_ID property on all atoms if M2IO_DATA_CT_ENTRY_ID property exists.
In Maestro, atom entry ids should be set automatically and there should never be a need to call this function. Explicit calls to this function are typically only required in unit tests.
- Parameters
st (schrodinger.structure.Structure) – The structure object
- class schrodinger.structure._ReaderWriterContextManager¶
Bases:
object
A mixin to enable context manager usage in reader and writer classes.
- class schrodinger.structure.MaestroTextReader(filename, index=1, error_handler=None)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
A class for reading structures from a Maestro format file. The structures returned are TextualStructure objects. These allow read-only access to the Structure-level properties but not to atoms or any properties which rely on atoms.
- read_mode = 16¶
- __init__(filename, index=1, error_handler=None)¶
Initialize the reader.
- Parameters
filename (string) – The filename to read.
index (int) – The index of the first structure to read.
error_handler (int) – The handle of the mmerr object to use for error logging. Defaults to schrodinger.infra.mm.error_handler.
- close()¶
Close the file.
- static read(filename: str, index: int = 1)¶
Allows users to read a single structure from the file
- Parameters
filename – The filename to read.
index – The index of the structure to read. NOTE: index is 1-based
- class schrodinger.structure.MaestroReader(filename, index=1, error_handler=None, input_string=None)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
A class for reading structures from a Maestro (M2io) format file.
- __init__(filename, index=1, error_handler=None, input_string=None)¶
Initialize the reader.
- Parameters
filename (string) – The filename to read.
index (int) – The index of the first structure to read.
error_handler (int) – The handle of the mmerr object to use for error logging. Defaults to schrodinger.infra.mm.error_handler.
input_string (string) – A string with the contents of a Maestro format file. If provided, the filename argument is ignored.
- getErrorHandler()¶
Returns the error handler that is in use by m2io.
- seek(position)¶
Set the file position to the given position in bytes. This raise an exception for zero size file.
- read(position=None)¶
Return the next Structure object. If position is given, this will be honoured. Otherwise the current position is taken. This raise an exception for zero size file, reading structure beyond end of file indicator and m2io errors.
- Raises
EOFError – on EOF or zero size file.
Exception – otherwise.
- close()¶
Close the file.
- class schrodinger.structure.OptionError¶
Bases:
Exception
A parent exception class to indicate an error in setting an option.
- class schrodinger.structure.UnsupportedOption(option_name, class_name)¶
Bases:
schrodinger.structure._io.OptionError
An exception class to indicate an attempt to set an option that is not supported.
- __init__(option_name, class_name)¶
- class schrodinger.structure.UnsupportedOptionValue(option_name, option_value, class_name)¶
Bases:
schrodinger.structure._io.OptionError
An exception class to indicate an attempt to set an option to a value that is supported.
- __init__(option_name, option_value, class_name)¶
- class schrodinger.structure._BaseWriter¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
This class provides a common implementation for structure writers.
- setOption(option, value)¶
Set a single option for this writer. This method is meant for options that may not be supported for all writer formats. See the
StructureWriter
class documentation for details on the available options.Raises an OptionError subclass (either UnsupportedOption or UnsupportedOptionValue) if unsuccessful.
- Parameters
option (str) – The name of the option to set.
value – The value for the option. The data type of this parameter depends on the option being set.
- class schrodinger.structure.MaestroWriter(filename, overwrite=True, allow_empty_file=False)¶
Bases:
schrodinger.structure._io._BaseWriter
A class for more efficient appending of a large number of structures to a single maestro structure file.
For writing single structures, just use the Structure.write method. For appending a small (less than a thousand) number of structures, the Structure.append method will perform acceptably.
- __init__(filename, overwrite=True, allow_empty_file=False)¶
Initialize needed mmlibs and open the file ‘filename’.
Note that the file will not be completely written until it is explicitly closed or the object is garbage collected.
- Parameters
filename (str) – The filename to write to.
overwrite (bool) – If False, append to an existing file if it exists.
allow_empty_file (bool) – Whether we should create an output with no structures if we don’t append any structures.
- append(ct)¶
Append the provided structure to the open mae file. Set self.last_position to the file offset just before it was appended.
The use of this class and method should be preferred for large numbers of structures (say, >1000), but for smaller numbers of structures you can use the Structure.append method directly.
- close()¶
Close the file.
- class schrodinger.structure.Mol2Writer(filename, overwrite=True)¶
Bases:
schrodinger.structure._io.StructureWriter
Mol2 support for the StructureWriter class.
- __init__(filename, overwrite=True)¶
- Parameters
filename (str) – The filename to write to.
overwrite (bool) – If False, append to an existing file if it exists.
- class schrodinger.structure.PDBWriter(filename, reorder_by_sequence=False, first_occ=False, translate_pdb_resnames=True)¶
Bases:
schrodinger.structure._io._BaseWriter
A class for writing PDB-formatted files. Only one structure can be written to a PDB file. While this class overs no speed increase over the Structure.write() method, it provides more options.
- __init__(filename, reorder_by_sequence=False, first_occ=False, translate_pdb_resnames=True)¶
Initialize needed mmlibs and open the file ‘filename’.
Note that the file will not be completely written until it is explicitly closed or the object is garbage collected.
- Parameters
filename (str) – The filename to write to.
reorder_by_sequence (bool) – Whether to re-order the residues by sequence before writing the PDB file.
first_occ (bool) – If True and there are alternate occupancy sites, only the first occupancy site will be included in the output PDB file. Otherwise, all occupancy sites will be included.
translate_pdb_resnames (bool) – If True, the pdb residue names get converted to a standard set. If False, the translation is turned off.
NOTE: Any existing file will be overwritten when the class instance is created.
- write(ct)¶
Write the provided structure to the PDB file.
- append(ct)¶
Alias to the write() method (for consistency with the other Writer classes).
- close()¶
Does nothing. Added for consistency with other Writer classes.
- class schrodinger.structure.MMCIFWriter(filename)¶
Bases:
schrodinger.structure._io._BaseWriter
Write a structure to macromolecular cif aka pdbx format.
Suitable for use with applications that expect the cif format used by the RCSB PDB, for instance. Can be read by the Schrodinger .cif reader.
Currently uses openbabel and .pdb as a shim.
- __init__(filename)¶
- Parameters
filename (str) – Name of file to which structures should be written
- write(st)¶
Write a Structure to the file specified in the constructor.
- Parameters
st (
schrodinger.Structure
) – Structure to write to a file
- append(st)¶
- class schrodinger.structure.CIFWriter(filename)¶
Bases:
schrodinger.structure._io.MMCIFWriter
Write a structure to small-molecule cif format.
Suitable for use with applications that expect the cif format used by the Cambridge Crystalographic Database, for instance. Can be read by the Schrodinger .cif reader.
Currently uses openbabel and .pdb as a shim.
- class schrodinger.structure.StructureWriter(filename, overwrite=True, format=None, stereo=None, allow_empty_file=False)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
A class for efficient writing of multiple structures to a single structure file. If you are writing a single structure, you can more easily use the
Structure.write
method.Options that are not supported for all formats can be set with the setOption method, for example:
writer = StructureWriter(filename) try: writer.setOption(stereo=STEREO_FROM_ANNOTATION) except OptionError: # take action based on unsupported option/value here
Currently, the following options are available:
stereo
This option controls how stereochemical properties are written. It does not affect the output geometry.
This option is supported for
SD
,SMILES
, andSMILESCSV
, although not all options are supported forSD
.Option values are
NO_STEREO
,STEREO_FROM_ANNOTATION_AND_GEOM
,STEREO_FROM_ANNOTATION
, andSTEREO_FROM_GEOMETRY
.The default value is
STEREO_FROM_ANNOTATION_AND_GEOM
.With
STEREO_FROM_ANNOTATION_AND_GEOM
, current annotation properties of the Structure are used when present. Chiral atoms without annotation properties will have their stereochemistry determined from geometry (if possible) and will be written with definite stereochemical configuration.With
NO_STEREO
, no stereochemical information will be written.With
STEREO_FROM_ANNOTATION
, stereochemical information will be written based only on the current annotations. Use this option to allow for specification of stereochemistry on some centers while leaving others undefined. This should be faster than identifying stereochemistry from the 3D geometry.With
STEREO_FROM_GEOMETRY
, stereochemistry will be written for all chiral atoms based on the 3D geometry. This option is not supported forSD
format.
- __init__(filename, overwrite=True, format=None, stereo=None, allow_empty_file=False)¶
Create a structure writer class based on the format.
- Parameters
filename (str or pathlib.Path) – The filename to write to.
overwrite (bool) – If False, append to an existing file instead of overwriting it.
format (str) – The format of the file. Values should be specified by one of the module-level constants MAESTRO, MOL2, SD, SMILES, or SMILESCSV. If the format is not explicitly specified it will be determined from the suffix of the filename. Multi-structure PDB files are not supported.
stereo (enum) –
Use of the stereo option in the constructor is pending deprecation. Please use the setOption method instead.
See the class docstring for documentation on the stereo options.
allow_empty_file (bool) – whether we should create a file with no structures if we don’t append any structures. Only a valid option for Maestro files.
- append(ct)¶
Append the provided structure to the open file.
- extend(cts)¶
Append all provided structures to the open file.
- close()¶
Close the file.
- setOption(option, value)¶
Set a single option for this writer. This method is meant for options that may not be supported for all writer formats. See the
StructureWriter
class documentation for details on the available options.Raises an OptionError subclass (either UnsupportedOption or UnsupportedOptionValue) if unsuccessful.
- Parameters
option (str) – The name of the option to set.
value – The value for the option. The data type of this parameter depends on the option being set.
- static write(st, filename)¶
Writes the given Structure to the specified file, overwriting the file if it already exists.
- Parameters
st (structure.Structure) – structure object to write to file
filename (str or pathlib.Path) – filename to write to
- class schrodinger.structure.SDWriter(filename, overwrite=True)¶
Bases:
schrodinger.structure._io.StructureWriter
A class for more efficient appending of a large number of structures to a single SD structure file.
For writing single structures, just use the Structure.write method. For appending a small (less than a thousand) number of structures, the Structure.append method will perform acceptably.
- __init__(filename, overwrite=True)¶
- Parameters
filename (str) – The filename to write to.
overwrite (bool) – If False, append to an existing file if it exists.
- class schrodinger.structure.PDBReader(filename, index=1, error_handler=None, all_occ=True, use_strict_resname=False)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
A class for reading structures from a PDB format file.
- __init__(filename, index=1, error_handler=None, all_occ=True, use_strict_resname=False)¶
Initialize with a filename, an optional starting index (default of 1) and optional error_handler (default of mm.error_handler).
all_occ - Whether to include alternative positions (default=True)
- use_strict_resname - Limit the residue name to 18-20 columns of pdb
record.
- close()¶
Close the file.
- getErrorHandler()¶
Returns the error handler by querying the pdb library and if the refcount is > 0 then return the error handler that is in use by pdb. Otherwise None is returned.
- class schrodinger.structure.StructureReader(filename, index=1)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
Read structures from files of various types.
Example usage:
# Read the first structure in a file: st = structure.StructureReader.read('myfile.pdb') # Read all structures from a file: for st in structure.StructureReader('myfile.sdf'): <do something with st> # Start reading at the second structure entry in the file for st in structure.StructureReader('myfile.sdf', index=2): <do something with st> # Assign iterator to a variable and read first 2 structures: st_reader = structure.StructureReader('myfile.mae') st1 = next(st_reader) st2 = next(st_reader)
- __init__(filename, index=1)¶
- setIndex(index)¶
- close()¶
- static read(filename, index=1)¶
Reads the first Structure from the given file.
- Parameters
filename (str or pathlib.Path) – filename to read from
index (int) – the positional index of the structure to read
- Returns
first structure from the given file
- Return type
- static fromString(input_string, index=1, format='maestro')¶
Creates a reader iterator from an input string. This is only supported for Maestro and SD formats.
- Parameters
input_string (str) – the string representation of the Structure.
index (int) – the index of the first structure to read.
format (str) – the string format, either MAESTRO or SD.
- schrodinger.structure.write_cts(sts, filename)¶
Write multiple structures to a file
- Parameters
sts (iter) – An iterable containing the structures to write
filename (str) – The filename to write the structures to. File format will be determined from the filename suffix.
- schrodinger.structure.get_structures_from_bytes(str_data: bytes) List[schrodinger.structure._structure.Structure] ¶
Read structures from bytes string and return a list of structure.Structure objects.
- Parameters
str_data – is the bytes string containing the structures
- Returns
a list of structure.Structure objects
- schrodinger.structure.count_structures(filename)¶
Returns the number of structures in the specified file. For PDB files, returns the number of MODELs. Optionally an error_handler may be specified (default of mm.error_handler).
- class schrodinger.structure.TextualStructure(ct, txt)¶
Bases:
schrodinger.structure._structure.Structure
A sub-class of Structure for use when reading from a Maestro format file and only the structure-level properties are needed. The actual atom and bond records are not parsed from the file and so can’t actually be accessed. The only things possible with this type of Structure are to access the structure level properties or to write it out unchanged to a file. Attempts to access the atom or bond data, directly or indirectly, will raise an exception.
The only useful way to create a TextualStructure object is via the MaestroTextReader.
- __init__(ct, txt)¶
Initialize the TextualStructure object. The Structure handle will usually have no atoms but will have an unrequested data handle associated with it which can be used to access the Structure-level properties. ‘txt’ should be the full textual representation of the f_m_ct block as read from the Maestro format file.
- property atom¶
An iterable of structure atoms, each of which is a
StructureAtom
instance.Example usage, where
st
is a Structure instance:# Access an atom (indices start at 1) atomobj = st.atom[n] # Delete an atom del st.atom[n] # Find the number of atoms len(st.atom) # Iterate over all atoms for atom in st.atom: take_some_action(atom)
- Note
As with many other collections, the contents of the atom list should not be modified through additions or deletions while you are iterating over it.
- property atom_total¶
Get total number of atoms in this structure
- property molecule¶
An iterable of molecules in the structure, each of which is a
_Molecule
instance.Example usage:
# Find the number of molecules in the structure len(st.molecule) # Retrieve a molecule by number (indices start at 1) mol = st.molecule[molnum] # Iterate over all molecules for mol in st.molecule: take_some_action(mol)
- Note
Atoms and bonds should not be added or deleted while you are iterating over molecules.
- property chain¶
An iterable of chains in the structure, each of which is a
_Chain
instance.Example usage:
# Find the number of chains in the structure len(st.chain) # Retrieve a _Chain instance by letter chain = st.chain[letter] # Iterate over chains for chain in st.chain: take_some_action(chain)
- Note
Atoms and bonds should not be added or deleted while you are iterating over chains.
- property residue¶
An iterable of residues in the structure, each of which is a
_Residue
instance.To iterate over all residues:
for residue in st.residue: take_some_action(residue)
- Note
Atoms and bonds should not be added or deleted while you are iterating over residues.
- Note
residues are not accessible by index. See
Structure.findResidue()
- property ring¶
An iterable of rings in the structure, each of which is a
_Ring
instance.To iterate over rings:
for ring in st.ring: take_some_action(ring)
- Note
Atoms and bonds should not be added or deleted while you are iterating over rings.
- property property¶
Dictionary-like container of structure properties. Keys are strings of the form
type_family_name
as described in thePropertyName
documentation.- Note
Unlike the
Structure.property
dictionary, this dictionary is read-only.
- write(filename, format=None)¶
Write the structure to a file, overwriting any previous content. File will only be written to Maestro format.
- append(filename, format=None)¶
Append the structure to the file. File will only be written to Maestro format.
- putToM2ioFile(filehandle)¶
Used by the Maestro writer - put a single structure to the (already open) filehandle
- closeBlockIfNecessary(filehandle)¶
Used by the Maestro writer to leave the header block if necessary. For Structure objects this is not needed so it only returns
- Deprecated
The method is currently no op
- getStructure()¶
Return a Structure object for this TextualStructure by parsing the internal text representation into an mmct.
- static read(filename)¶
Reads the first structure from a Maestro file. TextualStructure will only read from files in Maestro format.
- class schrodinger.structure.SmilesStructure(pattern, properties=None)¶
Bases:
object
SMILES representation of a Structure that is returned by SmilesReader and SmilesCsvReader. When written to a SMILES-formatted file, properties other than the title are not retained.
CXSMILES is also supported (the extension string is part of the ‘smiles’ member).
- mmsmiles_initialized = False¶
- __init__(pattern, properties=None)¶
- write(filename)¶
Write the structure to a SMILES formatted file.
- append(filename)¶
Append the structure to a SMILES formatted file.
- get2dStructure(add_hydrogens=False)¶
Return a 2D Structure object for this SMILES. The structure will have only 2D coordinates, with stereo annotation properties for chiral atoms with specified chirality. NOTE: Use for 2D applications only.
- Return type
- Returns
2D structure.
- Raises
ValueError – if self.smiles is set to an invalid SMILES string.
- get3dStructure(require_stereo=True)¶
Return a 3D Structure object for this SMILES with all hydrogens added.
- Parameters
require_stereo (bool) – Whether to require all chiral centers to have defined stereochemistry via annotation properties. Defaults to True. UndefinedStereochemistry exception is raised if any chiral atom has ambiguous chirality. If set to False, ambiguous chiralities will be expanded arbitrarily.
- Return type
- Returns
Volumized 3D structure.
- property title¶
- class schrodinger.structure.SmilesReader(filename, index=1)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
A class for reading structures from a SMILES formatted file. Returns instances of SmilesStructure.
When the USE_RDKIT_FOR_SMILESSTRUCTURE feature flag is enabled, this class will parse CXSMILES strings.
- __init__(filename, index=1)¶
Initialize with a filename, an optional starting index (default of 1).
- createSmilesStructure(pattern, properties)¶
Return a SmilesStructure object with the given pattern and properties.
- class schrodinger.structure.SmilesCsvReader(filename, index=1)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
A class for reading structures from a SMILES CSV formatted file. This format is used by Canvas. Returns instances of SmilesStructure.
When the USE_RDKIT_FOR_SMILESSTRUCTURE feature flag is enabled, this class will parse CXSMILES strings. The extension string must be part of the SMILES field, and must be enclosed in double quotes in case it contains any commas.
- __init__(filename, index=1)¶
Initialize with a filename, an optional starting index (default of 1).
- close()¶
- class schrodinger.structure.SmilesWriter(filename, overwrite=True, stereo=None)¶
Bases:
schrodinger.structure._io._BaseWriter
More efficient writing of a large number of structures to a single SMILES file.
- __init__(filename, overwrite=True, stereo=None)¶
- Parameters
filename (str) – The filename to write to.
overwrite (bool) – If False, append to an existing file if it exists.
stereo (enum) – See the
StructureWriter
class for documentation on the allowed values.
- append(st: Union[schrodinger.structure._io.SmilesStructure, schrodinger.structure._structure.Structure])¶
Append the provided structure to the open SMILES file.
- close()¶
Close the file.
- class schrodinger.structure.SmilesCsvWriter(filename, stereo=None, props=None)¶
Bases:
schrodinger.structure._io._BaseWriter
More efficient writing of a large number of structures to a single SMILES CSV file.
- __init__(filename, stereo=None, props=None)¶
- Note
Excessive memory may be used by this class if the props argument is not specified and many structures are appended.
- Parameters
filename (str) – The filename to write to.
stereo (enum) – See the
StructureWriter
class for documentation on the allowed values.props (list) – List of property names to export. If specified, then the CSV header is derived from this list, and structure lines are written by the append() method. If not specified, then CSV header will include all properties of all structures, and the output file will only be written when the close() method is called. (All structures will be cached in memory until flushed to disk.)
- append(st: Union[schrodinger.structure._io.SmilesStructure, schrodinger.structure._structure.Structure])¶
Append the provided structure to the open SMILES CSV file.
- close()¶
Close the file and write the data if props was computed on the fly.
- class schrodinger.structure.MultiFileStructureReader(files, *args, **kwargs)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
Provides a single iterator that reads structure from multiple files. Typical usage is identical to typical usage of the StructureReader class except that the class is instantiated with a python list of file names rather than a single file name.
By default, the StructureReader class is used to read the files, but this is customizable with the reader_class keyword.
API Example:
names = ['file1.mae', 'file2.mae', 'file3.pdb'] reader = MultiFileStructureReader(names) first_struct = next(reader) for struct in reader: do stuff
By default, the reader skips files that raise Exceptions and stores the list of skipped files in the failed_files property.
The current StructureReader can be accessed with the reader property
- __init__(files, *args, **kwargs)¶
Create a MultiFileStructureReader
- Parameters
files (list) – A list of paths to files to be read
reader_class (Reader class) – By default, StructureReader is used to read the files. A more specific class can be provided, such as PDBReader
pass_errors (bool) – If True, any filename that raises an expected exception will be skipped. Skipped filenames are stored in the failed_files property and can be retrieved after reading. Items of the failed_files list are tuples (filename, error_message). Expected Exceptions include: IOError (does not exist, or unreadable), ValueError (unknown extension), MmException (error opening file) or an Exception while reading structures. The default of False will cause the exceptions to be raise’d.
skip_receptors (bool) – Whether to skip receptors of PV files.
Any additional parameters and keyword arguments are passed to the structure reader class.
- reader_class¶
The class used to read files
- pass_errors¶
False if exceptions should be raised, True if they should be caught
- files¶
List of files remaining to be read
- current_filename¶
The file currently being read
- index_in_current_file¶
Index of current structure in current file
- failed_files¶
List of (failed_file_name, error_message)
- reader¶
Current file reader
- class schrodinger.structure.MultiFileStructureWriter(basename, extension='.maegz', sts_per_file=100000)¶
Bases:
schrodinger.structure._io._ReaderWriterContextManager
Similar to StructureWriter, except that it writes to multiple files, while keeping the number of structures per file under sts_per_file.
Files will be named <basename>-NNN<extension>. Default extension is .maegz.
Options:
basename - The base name of the written files extension - The extension of the written files (default “.maegz”) sts_per_file - Maximum number of structures to write to each file
Usage:
writer = MultiFileStructureWriter(out_basename, ".maegz", 50) for st in sts: writer.append(st) writer.close() written_files = writer.getFiles()
- __init__(basename, extension='.maegz', sts_per_file=100000)¶
- append(st)¶
- getFiles()¶
Return a list of file paths for the written files.
- getNumStructures()¶
Return the total number of structures that were written.
- close()¶
Close any open file handles