schrodinger.models.jsonable module

A module for defining jsonable versions of classes (typically classes defined in third-party modules).

You can also find the registry of classes that are supported by the load(s) and dump(s) functions in schrodinger.model.json. Any object that is an instance of one of the registered classes will be automatically jsonable using dump and dumps. To deserialize, you must specify the registered class to load or loads. Example:

from schrodinger.models import json
my_set = set(range(1,2,3))
my_set_jsonstr = json.dumps(my_set)
new_set = json.loads(my_set_jsonstr, DataClass=set)
assert new_set == my_set
assert isinstance(new_set, set)
Currently registered DataClasses:
  • structure.Structure

  • set

  • tuple

  • rdkit.Chem.rdchem.Mol

  • bytes

class schrodinger.models.jsonable.JsonableSet

Bases: schrodinger.models.json.JsonableClassMixin, set

ENCODING_KEY = '_python_set_'
toJsonImplementation()

Abstract method that must be defined by all derived classes. Converts an instance of the derived class into a jsonifiable object.

Returns

A dict made up of JSON native datatypes or Jsonable objects. See the link below for a table of such types. https://docs.python.org/2/library/json.html#encoders-and-decoders

classmethod fromJsonImplementation(json_list)

Abstract method that must be defined by all derived classes. Takes in a dictionary and constructs an instance of the derived class.

Parameters

json_dict (dict) – A dictionary loaded from a JSON string or file.

Returns

An instance of the derived class.

Return type

cls

copy()

Return a shallow copy of a set.

__contains__()

x.__contains__(y) <==> y in x.

__init__(*args, **kwargs)
__len__()

Return len(self).

add()

Add an element to a set.

This has no effect if the element is already present.

clear()

Remove all elements from this set.

difference()

Return the difference of two or more sets as a new set.

(i.e. all elements that are in this set but not the others.)

difference_update()

Remove all elements of another set from this set.

discard()

Remove an element from a set if it is a member.

If the element is not a member, do nothing.

classmethod fromJson(json_obj)

A factory method which constructs a new object from a given dict loaded from a json string or file.

Parameters

json_obj (dict) – A json-loaded dictionary to create an object from.

Returns

An instance of this class.

Return type

cls

get_version()

Method to get the version of a particular object. Defaults to the current version of mmshare. This class can be overridden for custom versioning behavior.

intersection()

Return the intersection of two sets as a new set.

(i.e. all elements that are in both sets.)

intersection_update()

Update a set with the intersection of itself and another.

isdisjoint()

Return True if two sets have a null intersection.

issubset()

Report whether another set contains this set.

issuperset()

Report whether this set contains another set.

pop()

Remove and return an arbitrary set element. Raises KeyError if the set is empty.

remove()

Remove an element from a set; it must be a member.

If the element is not a member, raise a KeyError.

symmetric_difference()

Return the symmetric difference of two sets as a new set.

(i.e. all elements that are in exactly one of the sets.)

symmetric_difference_update()

Update a set with the symmetric difference of itself and another.

toJson(_mark_version=True)

Create and returns a data structure made up of jsonable items.

Return type

An instance of one the classes from NATIVE_JSON_DATATYPES

union()

Return the union of sets as a new set.

(i.e. all elements that are in either set.)

update()

Update a set with the union of itself and others.

class schrodinger.models.jsonable.JsonableStructure(handle, error_handler=None)

Bases: schrodinger.models.json.JsonableClassMixin, schrodinger.structure._structure.Structure

toJsonImplementation()

Abstract method that must be defined by all derived classes. Converts an instance of the derived class into a jsonifiable object.

Returns

A dict made up of JSON native datatypes or Jsonable objects. See the link below for a table of such types. https://docs.python.org/2/library/json.html#encoders-and-decoders

classmethod fromJsonImplementation(json_str)

Abstract method that must be defined by all derived classes. Takes in a dictionary and constructs an instance of the derived class.

Parameters

json_dict (dict) – A dictionary loaded from a JSON string or file.

Returns

An instance of the derived class.

Return type

cls

__init__(handle, error_handler=None)

Initialize an object with an existing MMCT handle or a C++ Structure object.

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.

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.

append(filename, format=None)

Convenience method for the preferred StructureWriter context manager

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.

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

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.

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.

areBound(atom1, atom2)

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

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

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.

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.

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

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.

deletePropertyFromAllAtoms(prop_name)

Deletes a property from all atoms present in structure

Param

prop_name: The name of the atom-level property to delete.

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.

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

Structure

Returns

Extracted structure

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.

property formal_charge

Get the sum of formal charges for the structure.

classmethod fromJson(json_obj)

A factory method which constructs a new object from a given dict loaded from a json string or file.

Parameters

json_obj (dict) – A json-loaded dictionary to create an object from.

Returns

An instance of this class.

Return type

cls

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.

get_version()

Method to get the version of a particular object. Defaults to the current version of mmshare. This class can be overridden for custom versioning behavior.

has3dCoords()

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

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

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.

property mol_total

Get total number of molecules 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.

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 the PropertyName documentation.

putToM2ioFile(filehandle)

Used by the Maestro writer - put a single structure to the (already open) filehandle

static read(filename, index=1)

Convenience method for the preferred call to StructureReader.read()

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

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.

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.

setXYZ(xyz)

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

property title

Get the title for this structure

toJson(_mark_version=True)

Create and returns a data structure made up of jsonable items.

Return type

An instance of one the classes from NATIVE_JSON_DATATYPES

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.

write(filename, format=None)

Convenience method for the preferred call to StructureWriter.write()

writeToString(format)

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

class schrodinger.models.jsonable.JsonableTuple(iterable=(), /)

Bases: schrodinger.models.json.JsonableClassMixin, tuple

ENCODING_KEY = '_python_tuple_'
toJsonImplementation()

Abstract method that must be defined by all derived classes. Converts an instance of the derived class into a jsonifiable object.

Returns

A dict made up of JSON native datatypes or Jsonable objects. See the link below for a table of such types. https://docs.python.org/2/library/json.html#encoders-and-decoders

classmethod fromJsonImplementation(json_list)

Abstract method that must be defined by all derived classes. Takes in a dictionary and constructs an instance of the derived class.

Parameters

json_dict (dict) – A dictionary loaded from a JSON string or file.

Returns

An instance of the derived class.

Return type

cls

__contains__(key, /)

Return key in self.

__len__()

Return len(self).

count(value, /)

Return number of occurrences of value.

classmethod fromJson(json_obj)

A factory method which constructs a new object from a given dict loaded from a json string or file.

Parameters

json_obj (dict) – A json-loaded dictionary to create an object from.

Returns

An instance of this class.

Return type

cls

get_version()

Method to get the version of a particular object. Defaults to the current version of mmshare. This class can be overridden for custom versioning behavior.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

toJson(_mark_version=True)

Create and returns a data structure made up of jsonable items.

Return type

An instance of one the classes from NATIVE_JSON_DATATYPES

class schrodinger.models.jsonable.JsonableBytes

Bases: schrodinger.models.json.JsonableClassMixin, bytes

toJsonImplementation() str

Abstract method that must be defined by all derived classes. Converts an instance of the derived class into a jsonifiable object.

Returns

A dict made up of JSON native datatypes or Jsonable objects. See the link below for a table of such types. https://docs.python.org/2/library/json.html#encoders-and-decoders

classmethod fromJsonImplementation(b64encoded_bytes: str)

Abstract method that must be defined by all derived classes. Takes in a dictionary and constructs an instance of the derived class.

Parameters

json_dict (dict) – A dictionary loaded from a JSON string or file.

Returns

An instance of the derived class.

Return type

cls

__contains__(key, /)

Return key in self.

__len__()

Return len(self).

capitalize() copy of B

Return a copy of B with only its first character capitalized (ASCII) and the rest lower-cased.

center(width, fillchar=b' ', /)

Return a centered string of length width.

Padding is done using the specified fill character.

count(sub[, start[, end]]) int

Return the number of non-overlapping occurrences of subsection sub in bytes B[start:end]. Optional arguments start and end are interpreted as in slice notation.

decode(encoding='utf-8', errors='strict')

Decode the bytes using the codec registered for encoding.

encoding

The encoding with which to decode the bytes.

errors

The error handling scheme to use for the handling of decoding errors. The default is ‘strict’ meaning that decoding errors raise a UnicodeDecodeError. Other possible values are ‘ignore’ and ‘replace’ as well as any other name registered with codecs.register_error that can handle UnicodeDecodeErrors.

endswith(suffix[, start[, end]]) bool

Return True if B ends with the specified suffix, False otherwise. With optional start, test B beginning at that position. With optional end, stop comparing B at that position. suffix can also be a tuple of bytes to try.

expandtabs(tabsize=8)

Return a copy where all tab characters are expanded using spaces.

If tabsize is not given, a tab size of 8 characters is assumed.

find(sub[, start[, end]]) int

Return the lowest index in B where subsection sub is found, such that sub is contained within B[start,end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

classmethod fromJson(json_obj)

A factory method which constructs a new object from a given dict loaded from a json string or file.

Parameters

json_obj (dict) – A json-loaded dictionary to create an object from.

Returns

An instance of this class.

Return type

cls

fromhex()

Create a bytes object from a string of hexadecimal numbers.

Spaces between two numbers are accepted. Example: bytes.fromhex(‘B9 01EF’) -> b’\xb9\x01\xef’.

get_version()

Method to get the version of a particular object. Defaults to the current version of mmshare. This class can be overridden for custom versioning behavior.

hex()

Create a str of hexadecimal numbers from a bytes object.

sep

An optional single character or byte to separate hex bytes.

bytes_per_sep

How many bytes between separators. Positive values count from the right, negative values count from the left.

Example: >>> value = b’xb9x01xef’ >>> value.hex() ‘b901ef’ >>> value.hex(‘:’) ‘b9:01:ef’ >>> value.hex(‘:’, 2) ‘b9:01ef’ >>> value.hex(‘:’, -2) ‘b901:ef’

index(sub[, start[, end]]) int

Return the lowest index in B where subsection sub is found, such that sub is contained within B[start,end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the subsection is not found.

isalnum() bool

Return True if all characters in B are alphanumeric and there is at least one character in B, False otherwise.

isalpha() bool

Return True if all characters in B are alphabetic and there is at least one character in B, False otherwise.

isascii() bool

Return True if B is empty or all characters in B are ASCII, False otherwise.

isdigit() bool

Return True if all characters in B are digits and there is at least one character in B, False otherwise.

islower() bool

Return True if all cased characters in B are lowercase and there is at least one cased character in B, False otherwise.

isspace() bool

Return True if all characters in B are whitespace and there is at least one character in B, False otherwise.

istitle() bool

Return True if B is a titlecased string and there is at least one character in B, i.e. uppercase characters may only follow uncased characters and lowercase characters only cased ones. Return False otherwise.

isupper() bool

Return True if all cased characters in B are uppercase and there is at least one cased character in B, False otherwise.

join(iterable_of_bytes, /)

Concatenate any number of bytes objects.

The bytes whose method is called is inserted in between each pair.

The result is returned as a new bytes object.

Example: b’.’.join([b’ab’, b’pq’, b’rs’]) -> b’ab.pq.rs’.

ljust(width, fillchar=b' ', /)

Return a left-justified string of length width.

Padding is done using the specified fill character.

lower() copy of B

Return a copy of B with all ASCII characters converted to lowercase.

lstrip(bytes=None, /)

Strip leading bytes contained in the argument.

If the argument is omitted or None, strip leading ASCII whitespace.

static maketrans(frm, to, /)

Return a translation table useable for the bytes or bytearray translate method.

The returned table will be one where each byte in frm is mapped to the byte at the same position in to.

The bytes objects frm and to must be of the same length.

partition(sep, /)

Partition the bytes into three parts using the given separator.

This will search for the separator sep in the bytes. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing the original bytes object and two empty bytes objects.

replace(old, new, count=- 1, /)

Return a copy with all occurrences of substring old replaced by new.

count

Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

If the optional argument count is given, only the first count occurrences are replaced.

rfind(sub[, start[, end]]) int

Return the highest index in B where subsection sub is found, such that sub is contained within B[start,end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

rindex(sub[, start[, end]]) int

Return the highest index in B where subsection sub is found, such that sub is contained within B[start,end]. Optional arguments start and end are interpreted as in slice notation.

Raise ValueError when the subsection is not found.

rjust(width, fillchar=b' ', /)

Return a right-justified string of length width.

Padding is done using the specified fill character.

rpartition(sep, /)

Partition the bytes into three parts using the given separator.

This will search for the separator sep in the bytes, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing two empty bytes objects and the original bytes object.

rsplit(sep=None, maxsplit=- 1)

Return a list of the sections in the bytes, using sep as the delimiter.

sep

The delimiter according which to split the bytes. None (the default value) means split on ASCII whitespace characters (space, tab, return, newline, formfeed, vertical tab).

maxsplit

Maximum number of splits to do. -1 (the default value) means no limit.

Splitting is done starting at the end of the bytes and working to the front.

rstrip(bytes=None, /)

Strip trailing bytes contained in the argument.

If the argument is omitted or None, strip trailing ASCII whitespace.

split(sep=None, maxsplit=- 1)

Return a list of the sections in the bytes, using sep as the delimiter.

sep

The delimiter according which to split the bytes. None (the default value) means split on ASCII whitespace characters (space, tab, return, newline, formfeed, vertical tab).

maxsplit

Maximum number of splits to do. -1 (the default value) means no limit.

splitlines(keepends=False)

Return a list of the lines in the bytes, breaking at line boundaries.

Line breaks are not included in the resulting list unless keepends is given and true.

startswith(prefix[, start[, end]]) bool

Return True if B starts with the specified prefix, False otherwise. With optional start, test B beginning at that position. With optional end, stop comparing B at that position. prefix can also be a tuple of bytes to try.

strip(bytes=None, /)

Strip leading and trailing bytes contained in the argument.

If the argument is omitted or None, strip leading and trailing ASCII whitespace.

swapcase() copy of B

Return a copy of B with uppercase ASCII characters converted to lowercase ASCII and vice versa.

title() copy of B

Return a titlecased version of B, i.e. ASCII words start with uppercase characters, all remaining cased characters have lowercase.

toJson(_mark_version=True)

Create and returns a data structure made up of jsonable items.

Return type

An instance of one the classes from NATIVE_JSON_DATATYPES

translate(table, /, delete=b'')

Return a copy with each character mapped by the given translation table.

table

Translation table, which must be a bytes object of length 256.

All characters occurring in the optional argument delete are removed. The remaining characters are mapped through the given translation table.

upper() copy of B

Return a copy of B with all ASCII characters converted to uppercase.

zfill(width, /)

Pad a numeric string with zeros on the left, to fill a field of the given width.

The original string is never truncated.

class schrodinger.models.jsonable.JsonableNamedTuple

Bases: schrodinger.models.json.JsonableClassMixin

A jsonabled NamedTuple that behaves like a normal named tuple but is jsonable if its fields are jsonable. Example:

class Coordinate(JsonableNamedTuple):
    x: float
    y: float
    description: str

coord = Coordinate(x=1, y=2, description="molecule coord")
assert coord == (1, 2, "molecule coord")
serialized_coord = json.dumps(c)
deserialized_coord = json.loads(serialized_coord, DataClass=Coordinate)
assert deserialized_coord == (1, 2, "molecule coord")
WARNING:: Instances of subclasses of this class will not evaluate as

instances of JsonableNamedTuple. This replicates the behavior of typing.NamedTuple.

classmethod fromJson(json_obj)

A factory method which constructs a new object from a given dict loaded from a json string or file.

Parameters

json_obj (dict) – A json-loaded dictionary to create an object from.

Returns

An instance of this class.

Return type

cls

classmethod fromJsonImplementation(json_dict)

Abstract method that must be defined by all derived classes. Takes in a dictionary and constructs an instance of the derived class.

Parameters

json_dict (dict) – A dictionary loaded from a JSON string or file.

Returns

An instance of the derived class.

Return type

cls

get_version()

Method to get the version of a particular object. Defaults to the current version of mmshare. This class can be overridden for custom versioning behavior.

toJson(_mark_version=True)

Create and returns a data structure made up of jsonable items.

Return type

An instance of one the classes from NATIVE_JSON_DATATYPES

toJsonImplementation()

Abstract method that must be defined by all derived classes. Converts an instance of the derived class into a jsonifiable object.

Returns

A dict made up of JSON native datatypes or Jsonable objects. See the link below for a table of such types. https://docs.python.org/2/library/json.html#encoders-and-decoders

class schrodinger.models.jsonable.JsonableEnum(value)

Bases: schrodinger.models.jsonable._JsonableEnumBase, enum.Enum

An enumeration.

__init__(*args, **kwargs)
classmethod fromJsonImplementation(json_obj)

Abstract method that must be defined by all derived classes. Takes in a dictionary and constructs an instance of the derived class.

Parameters

json_dict (dict) – A dictionary loaded from a JSON string or file.

Returns

An instance of the derived class.

Return type

cls

toJsonImplementation()

Abstract method that must be defined by all derived classes. Converts an instance of the derived class into a jsonifiable object.

Returns

A dict made up of JSON native datatypes or Jsonable objects. See the link below for a table of such types. https://docs.python.org/2/library/json.html#encoders-and-decoders

class schrodinger.models.jsonable.JsonableIntEnum(value)

Bases: int, schrodinger.models.json.JsonableClassMixin, enum.Enum

An enumeration.

__init__(*args, **kwargs)
classmethod fromJsonImplementation(json_obj)

Abstract method that must be defined by all derived classes. Takes in a dictionary and constructs an instance of the derived class.

Parameters

json_dict (dict) – A dictionary loaded from a JSON string or file.

Returns

An instance of the derived class.

Return type

cls

toJsonImplementation()

Abstract method that must be defined by all derived classes. Converts an instance of the derived class into a jsonifiable object.

Returns

A dict made up of JSON native datatypes or Jsonable objects. See the link below for a table of such types. https://docs.python.org/2/library/json.html#encoders-and-decoders

class schrodinger.models.jsonable.AbstractJsonSerializer

Bases: object

A class for defining how serialization should be done for a particular object. This should only be used if you’re unable to use json.JsonableClassMixin. This can be used in conjunction with json.load(s) and json.dump(s).

Subclasses must define ObjectClass and JsonableClass and override objectFromJsonable and jsonableFromObject.

Create a subclass here to add a new class to the global default serialization registry. (Consult with relevant parties before doing so…)

Variables
  • ObjectClass – The non-jsonable third-party class (e.g. set, rdkit.Mol, etc.)

  • JsonableClass – The class that subclasses ObjectClass and mixes in JsonableClassMixin.

ObjectClass = NotImplemented
JsonableClass = NotImplemented
__init__()
classmethod objectFromJsonable(jsonable_obj)

Return an instance of ObjectClass from an instance of JsonableClass

classmethod jsonableFromObject(obj)

Return an instance of JsonableClass from an instance of ObjectClass

classmethod objectFromJson(json_obj)

DO NOT OVERRIDE.

Return an instance of ObjectClass from a json object (i.e. an object made up of json native types).

class schrodinger.models.jsonable.StructureSerializer

Bases: schrodinger.models.jsonable.AbstractJsonSerializer

ObjectClass

alias of schrodinger.structure._structure.Structure

JsonableClass

alias of schrodinger.models.jsonable.JsonableStructure

classmethod objectFromJsonable(jsonable_structure)

Return an instance of ObjectClass from an instance of JsonableClass

classmethod jsonableFromObject(structure_)

Return an instance of JsonableClass from an instance of ObjectClass

__init__()
classmethod objectFromJson(json_obj)

DO NOT OVERRIDE.

Return an instance of ObjectClass from a json object (i.e. an object made up of json native types).

class schrodinger.models.jsonable.TupleSerializer

Bases: schrodinger.models.jsonable.AbstractJsonSerializer

ObjectClass

alias of tuple

JsonableClass

alias of schrodinger.models.jsonable.JsonableTuple

classmethod objectFromJsonable(jsonable_tuple)

Return an instance of ObjectClass from an instance of JsonableClass

classmethod jsonableFromObject(tuple_)

Return an instance of JsonableClass from an instance of ObjectClass

__init__()
classmethod objectFromJson(json_obj)

DO NOT OVERRIDE.

Return an instance of ObjectClass from a json object (i.e. an object made up of json native types).

class schrodinger.models.jsonable.BytesSerializer

Bases: schrodinger.models.jsonable.AbstractJsonSerializer

ObjectClass

alias of bytes

JsonableClass

alias of schrodinger.models.jsonable.JsonableBytes

classmethod objectFromJsonable(jsonable_bytes: schrodinger.models.jsonable.JsonableBytes) bytes

Return an instance of ObjectClass from an instance of JsonableClass

classmethod jsonableFromObject(bytes_) schrodinger.models.jsonable.JsonableBytes

Return an instance of JsonableClass from an instance of ObjectClass

__init__()
classmethod objectFromJson(json_obj)

DO NOT OVERRIDE.

Return an instance of ObjectClass from a json object (i.e. an object made up of json native types).

class schrodinger.models.jsonable.SetSerializer

Bases: schrodinger.models.jsonable.AbstractJsonSerializer

ObjectClass

alias of set

JsonableClass

alias of schrodinger.models.jsonable.JsonableSet

classmethod objectFromJsonable(jsonable_set)

Return an instance of ObjectClass from an instance of JsonableClass

classmethod jsonableFromObject(set_)

Return an instance of JsonableClass from an instance of ObjectClass

__init__()
classmethod objectFromJson(json_obj)

DO NOT OVERRIDE.

Return an instance of ObjectClass from a json object (i.e. an object made up of json native types).

class schrodinger.models.jsonable.MolSerializer

Bases: schrodinger.models.jsonable.AbstractJsonSerializer

ObjectClass

alias of rdkit.Chem.rdchem.Mol

JsonableClass

alias of schrodinger.models.jsonable._JsonableMolWrapper

classmethod objectFromJsonable(jsonable_mol)

Return an instance of ObjectClass from an instance of JsonableClass

classmethod jsonableFromObject(mol)

Return an instance of JsonableClass from an instance of ObjectClass

__init__()
classmethod objectFromJson(json_obj)

DO NOT OVERRIDE.

Return an instance of ObjectClass from a json object (i.e. an object made up of json native types).

schrodinger.models.jsonable.serializer

alias of schrodinger.models.jsonable.MolSerializer

schrodinger.models.jsonable.get_default_serializer(DataClass)