schrodinger.structure.structure module

A module containing the central interface for reading and editing chemical structures.

Structure is a pythonic, object oriented wrapper for the mmct library that provides access to atoms, bonds, and their properties. It provides common methods for inspecting and editing coordinates, e.g. Structure.measure, Structure.adjust, and Structure.merge. The schrodinger.structutils package provides additional functions and classes that operate on Structure objects.

StructureReader provides a convenient iterator to read structures from files, and StructureWriter provides an efficient means of writing many files.

PropertyName provides translation between m2io datanames and user friendly names.

MultiFileStructureReader iterates through all the structure in multiple files using StructureReader.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.structure.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.

schrodinger.structure.structure.suppress_error_reporting(error_handler)
schrodinger.structure.structure.get_atom_names_for_chi_angle(res_type, angle_name)

Return atom names for the specified Chi angle in the given residue type.

Parameters:
  • res_type (str) – Residue type (e.g. “ALA “)
  • angle_name (str) – Chi angle name. One of: Chi1, Chi2, Chi3, Chi4, Chi5. See CHI_DIHEDRAL_NAMES.
:raises ValueError if the given angle is invalid, or is not defined for the
given residue.
class schrodinger.structure.structure.BondType

Bases: enum.Enum

These represent varying bond types, which are independent from bond orders.

Zero = 0
Dative = 1
Single = 2
Double = 3
Triple = 4
exception schrodinger.structure.structure.UndefinedStereochemistry

Bases: Exception

Raised by SmilesStructure.getStructure() when atoms with undefined chirality are present.

__init__

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception schrodinger.structure.structure.AtomsInRingError

Bases: ValueError

Raised by Structure.adjust() when atoms are in a ring, so adjustment can’t be made without distorting the structure.

__init__

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class schrodinger.structure.structure.Structure(handle, error_handler=None)

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. The schrodinger.project module provides access to Structures in a Maestro project.

Properties of the Structure entry can be accessed from the property dictionary using the mae 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 the _StructureAtom class. See the “Properties” section of the schrodinger.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 the schrodinger.structure._StructureAtom.bond attribute. Like atoms, bonds have some built-in attributes and a general property dictionary. Bonds can also be accessed from the schrodinger.structure.Structure.bond iterator, which iterates over all bonds in the Structure.

Iterators for various substructures can be accessed from the molecule, chain, residue, and ring attributes. Each of these yields an object that has a getAtomIndices method to get a list of atom indices, and an extractStructure method that can be used to create a separate Structure instance corresponding to the substructure.

Please see the Python Module Overview for a non-technical introduction and additional examples.

__init__(handle, error_handler=None)

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.
title

Get the title for this structure

atom_total

Get total number of atoms in this structure

mol_total

Get total number of molecules in this structure

formal_charge

Get the sum of formal charges for the structure.

Accessing this property is an O(N) operation.

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.

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

Dictionary-like container of Structure-level properties. Keys are strings of the form type_family_name as described in the PropertyName 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, error_handler=None, format=None, ignore_errors=False)

Read a single structure from file ‘filename’, returning a Structure instance.

Parameters:
  • index (int) – For multi-structure formats, the index of the structure to read.
  • error_handler (int) – Handle of the mmerr object to use for error logging. Defaults to schrodinger.infra.mm.error_handler.
  • format (str) – Format of the file, either ‘pdb’, ‘sd’, ‘mol2’, ‘maestro’ or ‘maestro_text’ (determined from file extension by default).
  • ignore_errors (bool) – If True, bad structures will be skipped instead of raising an exception. Currently only used by the SD reader.
writeToString(format)

Write the structure to a string representation and return the string. The format parameter is required.

write(filename, format=None)

Write the structure to a file, overwriting any previous content. Format is determined from the file suffix if None is specified, otherwise an explicit value of maestro, sd, pdb, or smiles can be used.

append(filename, format=None)

Append the structure to the named file.

This method should provided acceptable performance if you are writing a small number of structures, but if you need to write a large number of structures (more than a few hundred) to a file, the StructureWriter class will provide better performance.

Parameters:format (str) – By default, the file format is determined from the filename suffix, but this can be specified explicitly. Supported option values are one of the PDB, MOL2, SD, MAESTRO, SMILES, SMILESCSV module-level constants.
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. The argument indices must be a sequence or an iterable, and able to be interpreted as ints.

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.

If copy_props is set to True, then the new structure object will inherit Structure-level properties from the source object.

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 be _StructureAtom 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.

All atom arguments can be integers or _StructureAtom objects. There is no return value for this function.

Raises:AtomsInRingError – if specified atoms are within a ring system. If ring distortion from an adjustment is not an issue, then the moving bitset can be manually created and passed to mmct_atom_set_distance(), mmct_atom_set_bond_angle(), or mmct_atom_set_dihedral_angle().
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.
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.
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.
class schrodinger.structure.structure.MaestroTextReader(filename, index=1, error_handler=None)

Bases: schrodinger.structure.structure._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.

class schrodinger.structure.structure.FormatReader(error_handler)

Bases: schrodinger.structure.structure._ReaderWriterContextManager

This is a base class for all file format readers.

It currently handles the queueing of error messages generated by the underlying file reading libraries.

__init__(error_handler)

Initialize self. See help(type(self)) for accurate signature.

getErrorHandler()

This method will return the current error handler. It should be defined in any derived class in order to query the appropriate mmlib and return the error handler if there is one.

getReadErrors()

Returns the list of error messages generated from the reading operations since the most recent clearReadErrors() call. Note that this could be an empty list if now errors have beenn encountered.

clearReadErrors()

Clears the list of read errors.

startErrorQueuing()

Queue error messages and suppress printing to the stream.

stopErrorQueuing()

Turn off error queueing and add any error messages to the error_queue attribute. And restore printing to the stream.

class schrodinger.structure.structure.InfraReader(filename)

Bases: schrodinger.structure.structure.FormatReader

Reader which uses c++ reader implementation.

NOTE: This is just tested for CIF format for now.

__init__(filename)

Initialize self. See help(type(self)) for accurate signature.

close()
clearReadErrors()

Clears the list of read errors.

getErrorHandler()

This method will return the current error handler. It should be defined in any derived class in order to query the appropriate mmlib and return the error handler if there is one.

getReadErrors()

Returns the list of error messages generated from the reading operations since the most recent clearReadErrors() call. Note that this could be an empty list if now errors have beenn encountered.

startErrorQueuing()

Queue error messages and suppress printing to the stream.

stopErrorQueuing()

Turn off error queueing and add any error messages to the error_queue attribute. And restore printing to the stream.

class schrodinger.structure.structure.MaeParserReader(filename, position=None)

Bases: schrodinger.structure.structure.InfraReader

Reader which uses C++ MaeParserReader implementation.

__init__(filename, position=None)

Initialize self. See help(type(self)) for accurate signature.

seek(position)
read(position=None)

Return the next Structure object. If position is given, this will be honored. Otherwise the current position is taken.

clearReadErrors()

Clears the list of read errors.

close()
getErrorHandler()

This method will return the current error handler. It should be defined in any derived class in order to query the appropriate mmlib and return the error handler if there is one.

getReadErrors()

Returns the list of error messages generated from the reading operations since the most recent clearReadErrors() call. Note that this could be an empty list if now errors have beenn encountered.

startErrorQueuing()

Queue error messages and suppress printing to the stream.

stopErrorQueuing()

Turn off error queueing and add any error messages to the error_queue attribute. And restore printing to the stream.

class schrodinger.structure.structure.MaestroReader(filename, index=1, error_handler=None, input_string=None)

Bases: schrodinger.structure.structure.FormatReader

A class for reading structures from a Maestro (M2io) format file.

read_mode = 16
__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 by querying the m2io library and if the refcount is > 0 then return the error handler that is in use by m2io. Otherwise None is returned.

seek(position)

Set the file position to the given position. 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.

clearReadErrors()

Clears the list of read errors.

getReadErrors()

Returns the list of error messages generated from the reading operations since the most recent clearReadErrors() call. Note that this could be an empty list if now errors have beenn encountered.

startErrorQueuing()

Queue error messages and suppress printing to the stream.

stopErrorQueuing()

Turn off error queueing and add any error messages to the error_queue attribute. And restore printing to the stream.

exception schrodinger.structure.structure.OptionError

Bases: Exception

A parent exception class to indicate an error in setting an option.

__init__

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception schrodinger.structure.structure.UnsupportedOption(option_name, class_name)

Bases: schrodinger.structure.structure.OptionError

An exception class to indicate an attempt to set an option that is not supported.

__init__(option_name, class_name)

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception schrodinger.structure.structure.UnsupportedOptionValue(option_name, option_value, class_name)

Bases: schrodinger.structure.structure.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)

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class schrodinger.structure.structure.MaestroWriter(filename, overwrite=True)

Bases: schrodinger.structure.structure._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)

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.
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.

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.structure.SDWriter(filename, overwrite=True)

Bases: schrodinger.structure.structure._BaseWriter

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.

class Options

Bases: str, enum.Enum

An enumeration.

stereo = 'stereo'
assume_3d = 'assume_3d'
write_v3000 = 'write_v3000'
__init__(filename, overwrite=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.
  • overwrite (bool) – If False, append to an existing file if it exists.
setOption(option, value)

Set an option not supported for all StructureWriter formats.

The supported options for SDWriter are:

  • SDWriter.Options.stereo: NO_STEREO, STEREO_FROM_ANNOTATION, STEREO_FROM_ANNOTATION_AND_GEOM
  • SDWriter.Options.assume_3d: True (default), False
  • SDWriter.Options.write_v3000: True, False (default, only write V3000 for large
    structures)
append(ct)

Append the provided structure to the open file.

close()

Close the file.

class schrodinger.structure.structure.Mol2Writer(filename, overwrite=True)

Bases: schrodinger.structure.structure._BaseWriter

Mol2 support for the StructureWriter class.

__init__(filename, overwrite=True)

Initialize needed mmlibs and open the file ‘filename’.

Parameters:
  • filename (str) – The filename to write to.
  • overwrite (bool) – If False, append to an existing file if it exists.
append(st)

Append the provided structure to the file.

close()
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.structure.PDBWriter(filename, reorder_by_sequence=False, first_occ=False, translate_pdb_resnames=True)

Bases: schrodinger.structure.structure._ReaderWriterContextManager

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.structure.StructureWriter(filename, overwrite=True, format=None, stereo=None)

Bases: schrodinger.structure.structure._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, and SMILESCSV, although not all options are supported for SD.
    • Option values are NO_STEREO, STEREO_FROM_ANNOTATION_AND_GEOM, STEREO_FROM_ANNOTATION, and STEREO_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 for SD format.
__init__(filename, overwrite=True, format=None, stereo=None)

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.

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.
class schrodinger.structure.structure.PDBReader(filename, index=1, error_handler=None, all_occ=True, allow_obsolete=True, use_strict_resname=False)

Bases: schrodinger.structure.structure.FormatReader

A class for reading structures from a PDB format file.

__init__(filename, index=1, error_handler=None, all_occ=True, allow_obsolete=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)

allow_obsolete - Whether to allow reading obsolete PDB files
(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.

clearReadErrors()

Clears the list of read errors.

getReadErrors()

Returns the list of error messages generated from the reading operations since the most recent clearReadErrors() call. Note that this could be an empty list if now errors have beenn encountered.

startErrorQueuing()

Queue error messages and suppress printing to the stream.

stopErrorQueuing()

Turn off error queueing and add any error messages to the error_queue attribute. And restore printing to the stream.

class schrodinger.structure.structure.SDReader(filename, index=1, error_handler=None, ignore_errors=False, input_string=None, import_sdprop_as_string=False, import_sdprop_per_file=True, ignore_structureless=True)

Bases: schrodinger.structure.structure.FormatReader

A class for reading structures from a SD format file.

__init__(filename, index=1, error_handler=None, ignore_errors=False, input_string=None, import_sdprop_as_string=False, import_sdprop_per_file=True, ignore_structureless=True)

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.
  • ignore_errors (bool) – If True, bad structures will be skipped instead of raising an exception. If False, the caller may set self._previous_structure to None to continue reading past the error.
  • ignore_structureless (bool) – If False, exception will be raised for SD entries without atoms in case ignore_errors is also False (ignore_errors takes precedence, ignore_structureless makes atomless entries to be considered as errors).
  • input_string (string) – A string with the contents of an SD format file. If provided, the filename argument is ignored.
  • import_sdprop_as_string (bool) – Import all properties as strings. Setting this to True speeds file reading.
  • import_sdprop_per_file (bool) – Setting this to True indicates that all structures in the file will have the same set of properties. If this can be guaranteed, it speeds file reading.
getErrorHandler()

Returns the error handler by querying the mmmdl library and if the refcount is > 0 then return the error handler that is in use by mmmdl. Otherwise None is returned.

close()

Close the file.

clearReadErrors()

Clears the list of read errors.

getReadErrors()

Returns the list of error messages generated from the reading operations since the most recent clearReadErrors() call. Note that this could be an empty list if now errors have beenn encountered.

startErrorQueuing()

Queue error messages and suppress printing to the stream.

stopErrorQueuing()

Turn off error queueing and add any error messages to the error_queue attribute. And restore printing to the stream.

class schrodinger.structure.structure.Mol2Reader(filename, index=1, error_handler=None)

Bases: schrodinger.structure.structure.FormatReader

A class for reading structures from a mol2 format file.

__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.

getErrorHandler()

Returns the error handler by querying the mmmmol2 library and if the refcount is > 0 then return the error handler that is in use by mmmol2. Otherwise None is returned.

clearReadErrors()

Clears the list of read errors.

getReadErrors()

Returns the list of error messages generated from the reading operations since the most recent clearReadErrors() call. Note that this could be an empty list if now errors have beenn encountered.

startErrorQueuing()

Queue error messages and suppress printing to the stream.

stopErrorQueuing()

Turn off error queueing and add any error messages to the error_queue attribute. And restore printing to the stream.

class schrodinger.structure.structure.StructureReader(filename=None, index=1, error_handler=None, format=None, ignore_errors=False, input_string=None)

Bases: schrodinger.structure.structure._ReaderWriterContextManager

Read structures from files of various types.

The format is automatically determined from the extension of the specified file, or can be specified via the format option.

Example usage:

# Read the first structure in a file:
st = next(structure.StructureReader('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=None, index=1, error_handler=None, format=None, ignore_errors=False, input_string=None)

The format is determined from the file extension if no format is specified.

Parameters:
  • filename (str or pathlib.Path) – 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.
  • format (str) – The format of the file, either ‘pdb’, ‘sd’, ‘mol2’, ‘maestro’ or ‘maestro_text’ (determined from file extension by default).
  • ignore_errors (bool) – If True, bad structures will be skipped instead of raising an exception. Currently only used by the SD reader.
  • input_string (str) – Use of this argument is pending deprecation. Please use the StructureReader.fromString static method instead. If this is specified then the structure will be read from this string and the filename will be ignored. The format must be specified. Currently this is only supported for Maestro and SD format.
static fromString(input_string, index=1, error_handler=None, format='maestro', ignore_errors=False)

Create a StructureReader from an input string. Currently this is only supported for Maestro and SD format.

Parameters:
  • input_string (str) – The string representation of the Structure.
  • 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.
  • format (str) – The format of the file, either SD (‘sd’) or MAESTRO (‘maestro’). Defaults to MAESTRO.
  • ignore_errors (bool) – If True, bad structures will be skipped instead of raising an exception. Currently only used by the SD reader.
close()
getReadErrors()

Return any queued read errors.

clearReadErrors()

Clear any queued read errors.

schrodinger.structure.structure.read_ct(filename, index=1, error_handler=None)

Read a Structure from file ‘filename’, defaulting to the first one found.

Use the StructureReader or MaestroReader to access multiple structures from a single file.

Deprecated:Use the static Structure.read method instead, as it handles multiple formats and avoids the deprecated ‘ct’ name.
schrodinger.structure.structure.write_ct_to_string(ct, error_handler=None)

Return a string representation of the provided Structure, formatted as a Maestro file.

schrodinger.structure.structure.write_ct_to_sd_string(ct, error_handler=None)

Return a string representation of the provided Structure, formatted as an SD file.

schrodinger.structure.structure.write_ct(ct, filename, mode=2, error_handler=None)

Write a Structure to a Maestro format file.

schrodinger.structure.structure.write_cts(cts, filename)

Write multiple structures to a file

Parameters:
  • cts (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.structure.write_ct_as_text(ct, filename, mode=2, error_handler=None)

Write a TextualStructure object to a Maestro format file.

schrodinger.structure.structure.write_ct_sd(ct, filename, mode=2, error_handler=None)

Write a Structure to a SD format file.

schrodinger.structure.structure.write_ct_mol2(ct, filename, mode=1, error_handler=None)

Write a Structure to a mol2 format file.

schrodinger.structure.structure.write_ct_pdb(ct, filename, mode='write', error_handler=None)

Write a Structure to a PDB format file.

schrodinger.structure.structure.write_ct_smiles(st, filename, mode='write')

Write a Structure object to a SMILES format file. Assumes that the input is a 3D file. If input is 2D (from SD file), then stereochemistry will be lost

schrodinger.structure.structure.count_structures(filename, error_handler=None, format=None)

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.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 form type_family_name, where type is a datatype indicator, family indicates the owner or creator of the property, and name is the name of the property. These strings are used as the keys in the property dictionary attributes of Structure, _StructureAtom, and _StructureBond. Examples include s_m_title, which is a string created by Maestro with the name “title”, and i_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 equivalently PROP_REAL), PROP_INTEGER, and PROP_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

class schrodinger.structure.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 Strucure 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 StructureReader with the ‘maestro_text’ format.

__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.

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.
atom_total

Get total number of atoms in this structure

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.
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()
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

Dictionary-like container of structure properties. Keys are strings of the form type_family_name as described in the PropertyName 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

getStructure()

Return a Structure object for this TextualStructure by parsing the internal text representation into an mmct.

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
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.

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.

All atom arguments can be integers or _StructureAtom objects. There is no return value for this function.

Raises:AtomsInRingError – if specified atoms are within a ring system. If ring distortion from an adjustment is not an issue, then the moving bitset can be manually created and passed to mmct_atom_set_distance(), mmct_atom_set_bond_angle(), or mmct_atom_set_dihedral_angle().
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()
areBound(atom1, atom2)

Returns True if atom1 and atom2 have a bond of any order between them and False is there is no bond.

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.
copy()

Returns a copy of the structure.

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.

deleteBond(atom1, atom2)

Delete the bond between atom1 and atom2. Raises an Exception if there is no bond between these two.

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.
extract(indices, copy_props=False)

Return a new structure object which contains the atoms of the current structure that appear in the specified list. The argument indices must be a sequence or an iterable, and able to be interpreted as ints.

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.

If copy_props is set to True, then the new structure object will inherit Structure-level properties from the source object.

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.
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.
formal_charge

Get the sum of formal charges for the structure.

Accessing this property is an O(N) operation.

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.
get3dStructure(require_stereo=True)
Deprecated:Use generate3dConformation() instead.
getAtomIndices()

Return a list of all atom indices in this structure.

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.
getBond(atom1, atom2)

Returns a _StructureBond object for the bond between atom1 and atom2. The atom parameters can be _StructureAtom objects or integer indices from 1 to the number of atoms in the structure.

getChainAtoms(atom)

Return a list of atom objects that are in the same chain as ‘atom’.

getMoleculeAtoms(atom)

Return a list of atom objects that are in the same molecule as ‘atom’.

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.

getPropertyNames()
getResidueAtoms(atom)

Return a list of atom objects that are in the same residue as ‘atom’.

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.

has3dCoords()

Returns True if any atom in the structure has a non-zero z-coordinate.

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.

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.

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.

mol_total

Get total number of molecules in this structure

static read(filename, index=1, error_handler=None, format=None, ignore_errors=False)

Read a single structure from file ‘filename’, returning a Structure instance.

Parameters:
  • index (int) – For multi-structure formats, the index of the structure to read.
  • error_handler (int) – Handle of the mmerr object to use for error logging. Defaults to schrodinger.infra.mm.error_handler.
  • format (str) – Format of the file, either ‘pdb’, ‘sd’, ‘mol2’, ‘maestro’ or ‘maestro_text’ (determined from file extension by default).
  • ignore_errors (bool) – If True, bad structures will be skipped instead of raising an exception. Currently only used by the SD reader.
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.

setXYZ(xyz)

Set all xyz coordinates for the molecule from a numpy array.

title

Get the title for this structure

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.

writeToString(format)

Write the structure to a string representation and return the string. The format parameter is required.

class schrodinger.structure.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.

mmsmiles_initialized = False
__init__(pattern, properties=None)

Initialize self. See help(type(self)) for accurate signature.

write(filename)

Write the structure to a SMILES formatted file.

append(filename)

Append the structure to a SMILES formatted file.

get2dStructure()

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:Structure.Structure
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:Structure.Structure
Returns:Volumized 3D structure.
neutralize()

Neutralize this SMILES structure.

title
class schrodinger.structure.structure.SmilesReader(filename, index=1)

Bases: schrodinger.structure.structure._ReaderWriterContextManager

A class for reading structures from a SMILES formatted file. Returns instances of SmilesStructure.

__init__(filename, index=1)

Initialize with a filename, an optional starting index (default of 1).

class schrodinger.structure.structure.SmilesCsvReader(filename, index=1)

Bases: schrodinger.structure.structure._ReaderWriterContextManager

A class for reading structures from a SMILES CSV formatted file. This format is used by Canvas. Returns instances of SmilesStructure.

__init__(filename, index=1)

Initialize with a filename, an optional starting index (default of 1).

class schrodinger.structure.structure.SmilesWriter(filename, overwrite=True, stereo=None)

Bases: schrodinger.structure.structure._BaseWriter

More efficient writing of a large number of structures to a single SMILES 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.
__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)

Append the provided structure to the open SMILES file.

close()

Close the file.

class schrodinger.structure.structure.SmilesCsvWriter(filename, stereo=None, props=None)

Bases: schrodinger.structure.structure._BaseWriter

More efficient writing of a large number of structures to a single SMILES CSV 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.
__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)

Append the provided structure to the open SMILES CSV file.

close()

Close the file.

class schrodinger.structure.structure.MultiFileStructureReader(files, *args, **kwargs)

Bases: schrodinger.structure.structure._ReaderWriterContextManager

Provides a single iterator that reads structure from multiple files. Typical usage is idential to typical useage 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 reacer_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 = None

The class used to read files

pass_errors = None

False if exceptions should be raised, True if they should be caught

files = None

List of files remaining to be read

current_filename = None

The file currently being read

index_in_current_file = None

Index of current structure in current file

failed_files = None

List of (failed_file_name, error_message)

reader = None

Current file reader

class schrodinger.structure.structure.MultiFileStructureWriter(basename, extension='.maegz', sts_per_file=100000)

Bases: schrodinger.structure.structure._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)

Initialize self. See help(type(self)) for accurate signature.

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

schrodinger.structure.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 or Structure.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.structure.get_residues_by_connectivity(atom_container)

Access residues in N->C connectivity order

Parameters:atom_container (Structure._Chain, Structure._Structure, or Structure._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._ResidueIterator
schrodinger.structure.structure.get_residues_unsorted(atom_container)

Access residues in the unsorted input order

Parameters:atom_container (Structure._Chain, Structure._Structure, or Structure._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._ResidueIterator
schrodinger.structure.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