schrodinger.comparison.atom_mapper module

implementation of atom mapper used to perform comparisons and get atom mappings

class schrodinger.comparison.atom_mapper.MapScore(score, structure, atom_map)

Bases: tuple

__contains__

Return key in self.

__init__

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

__len__

Return len(self).

atom_map

Alias for field number 2

count(value) → integer -- return number of occurrences of value
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

score

Alias for field number 0

structure

Alias for field number 1

class schrodinger.comparison.atom_mapper.BaseAtomMapper(optimize_mapping, debug=False)

Bases: object

Base class for an atom mapper which reorders atoms in a Structure instance using graph isomorphism as implemented in networkx.

This class can be used to easily construct atom mapping algorithms and/or to determine if two structures are conformers. The essential features of implementing a new algorithm are to define an atom type (graph invariant) which identifies nodes and a method to score particular atom mappings. For more control one can also define new methods for creating and comparing graphs.

Once the abstract methods have been implemented in a subclass (call this MyAtomMapper for example) the mapper can be used to reorder the atoms of two structure instances such that there is a one-to-one correspondence between atom i in the first and second structure. That is, the atom map is applied to the structure:

mapper = MyAtomMapper(optimize_mapping=True) st1, st2 = mapper.reorder_atoms(st1, range(1, st1.atom_total + 1), st2, range(st2.atom_total + 1))

or two determine if the two structures are conformers: are_conformers = mapper.are_conformers(st1, range(1, st1.atom_total + 1), st2, range(st2.atom_total + 1))

ATOM_TYPE = 's_m_custom_atom_type'
MAPPER_INDEX = 'i_m_atom_mapper_index'
__init__(optimize_mapping, debug=False)
Parameters:
  • optimize_mapping (boolean) –
    if True search all possible bijections
    to deliver the one with the lowest score.

    if False, an arbitrary bijection (the first found) is returned.

  • debug (boolean) – print extra debugging information
initialize_atom_types(st, invert_stereocenters=False)

Initialize the atom types This method typically calls set_atom_type to store the atom types

Parameters:
  • st (Structure) – structure containing atoms to initial type of
  • invert_stereocenters (boolean) – whether or not R/S labels should be flipped
get_atom_type(at)

This value is used as an atom property

Parameters:at (_StructureAtom) – atom we wish to obtain a type for
Returns:string which identifies atom type
set_atom_type(at, value)

Set the value of the atom type

Parameters:
  • at (_StructureAtom) – atom we wish to set type for
  • value (string) – set the type of atom to this
score_mapping(st1, st2, atset)

Scores a particular atom reordering.

Parameters:
@pararm atset: the atoms which have been mapped. This may be a subset
of the atoms in the two structures as we test partial as well as full maps.
Returns:any metric which measures the goodness of a particular relative atom ordering in st1 and st2. Can be any type that has the less than operator implemented.
score_is_equivalent(score1, score2)

This defines if the two scores are actually equal. This helps to resolve machine dependent atom mappings in which two scores are very close to being equal but are not numerically equal. If this is an issue the this method can be implemented to return True if the two scores are within some numerical threshold and should be considered equal even if the less than operator considers them to not be equal.

for example if the two scores are 1.2e-8 and 1.4e-8 you may want to consider this method returning True.

Parameters:
  • score1 (a score (return type of score_mapping)) – the first score
  • score2 (a score (return type of score_mapping)) – the first score
unique_job_name(base_name)

Add an integer to the end of the base_name to get a unique name.

Parameters:base_name (str) – base job name
st_to_graph(st, atset)

Convert Structure instance to a networkx Graph using _StructureAtom instances as nodes and adding an atom type property

Parameters:
  • st (Structure) – the structure to convert
  • atset (set of ints) – a set of atoms to use to create the graph
Returns:

networkx Graph

comparator(d1, d2)

Comparison function to be used to determine if two nodes on graph are equivalent.

Parameters:
  • d1 (dict) – key=value dictionary from graph returned from st_to_graph which represents node 1
  • d1 – key=value dictionary from graph returned from st_to_graph which represents node 2
Returns:

boolean indicating equilvalence

isomeric_atom_sets(st1, atset1, st2, atset2)

Check that the atom types in atset1 are the same as those in atset2. If not, the two structures cannot be conformers.

Parameters:
  • st1 (Structure) – the first structure
  • atset1 (set of ints) – set of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atset2 (set of ints) – set of atom indexes defining the second substructure
Returns:

a boolean indicating if these atom lists are isomeric

invert_chirality(ch_list)

Invert the chirality (R/S) of an input list of chiralities.

Parameters:ch_list (list of strings) – list of chirality labels for a structure
are_conformers(st1, atlist1, st2, atlist2)

Determine if the two substructures, as defined by the atom lists, are conformers but do not explore isomorphisms.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

boolean indicating whether or not the two structures are conformers

are_enantiomers(st1, atlist1, st2, atlist2)

Determine if the two substructures, as defined by the atom lists, are enantiomers but do not explore isomorphisms.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

boolean indicating whether or not the two structures are conformers

reorder_structures(st1, atlist1, st2, atlist2, invert_stereocenters=False)

Reorder the atoms in the two structures.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

the two structures with structure 2 having had atoms reordered

class schrodinger.comparison.atom_mapper.ConnectivityAtomMapper(use_chirality)

Bases: schrodinger.comparison.atom_mapper.BaseAtomMapper

Used by comparison.py for comparison of conformers. Uses element types and optionally chirality to equate atoms and all bonds are considered equivalent.

Usage example: mapper = ConnectivityAtomMapper(use_chirality=False) st1, st2 = mapper.are_conformers(st1, range(1, st1.atom_total + 1), st2, range(st2.atom_total + 1))

__init__(use_chirality)
Parameters:use_chirality (boolean) – if True, in addition to element type use chirality (where defined) to equate atoms.
initialize_atom_types(st, invert_stereocenters=False)

Initialize the atom types

Parameters:
  • st (Structure) – structure containing atoms
  • invert_stereocenters (boolean) – whether or not R/S labels should be flipped
score_mapping(st1, st2, atset)

Score a mapping over the atoms in atset. This class is not intended for atom mapping problems but provide a score which is equal to the in place rmsd for testing purposes.

Parameters:
  • st1 (Structure) – first structure
  • st2 (Structure) – second structure
  • atset (set of ints) – set of atoms that have been mapped (indexes refer to both structures)
Returns:

an integer indicating the number of misaligned atom numbering stereocenters and a real representing the rmsd

score_is_equivalent(score1, score2)

determines if score should be considered equivalent

Parameters:
  • score1 (float) – the first score
  • score2 (float) – the second score
ATOM_TYPE = 's_m_custom_atom_type'
MAPPER_INDEX = 'i_m_atom_mapper_index'
are_conformers(st1, atlist1, st2, atlist2)

Determine if the two substructures, as defined by the atom lists, are conformers but do not explore isomorphisms.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

boolean indicating whether or not the two structures are conformers

are_enantiomers(st1, atlist1, st2, atlist2)

Determine if the two substructures, as defined by the atom lists, are enantiomers but do not explore isomorphisms.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

boolean indicating whether or not the two structures are conformers

comparator(d1, d2)

Comparison function to be used to determine if two nodes on graph are equivalent.

Parameters:
  • d1 (dict) – key=value dictionary from graph returned from st_to_graph which represents node 1
  • d1 – key=value dictionary from graph returned from st_to_graph which represents node 2
Returns:

boolean indicating equilvalence

get_atom_type(at)

This value is used as an atom property

Parameters:at (_StructureAtom) – atom we wish to obtain a type for
Returns:string which identifies atom type
invert_chirality(ch_list)

Invert the chirality (R/S) of an input list of chiralities.

Parameters:ch_list (list of strings) – list of chirality labels for a structure
isomeric_atom_sets(st1, atset1, st2, atset2)

Check that the atom types in atset1 are the same as those in atset2. If not, the two structures cannot be conformers.

Parameters:
  • st1 (Structure) – the first structure
  • atset1 (set of ints) – set of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atset2 (set of ints) – set of atom indexes defining the second substructure
Returns:

a boolean indicating if these atom lists are isomeric

reorder_structures(st1, atlist1, st2, atlist2, invert_stereocenters=False)

Reorder the atoms in the two structures.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

the two structures with structure 2 having had atoms reordered

set_atom_type(at, value)

Set the value of the atom type

Parameters:
  • at (_StructureAtom) – atom we wish to set type for
  • value (string) – set the type of atom to this
st_to_graph(st, atset)

Convert Structure instance to a networkx Graph using _StructureAtom instances as nodes and adding an atom type property

Parameters:
  • st (Structure) – the structure to convert
  • atset (set of ints) – a set of atoms to use to create the graph
Returns:

networkx Graph

unique_job_name(base_name)

Add an integer to the end of the base_name to get a unique name.

Parameters:base_name (str) – base job name
class schrodinger.comparison.atom_mapper.LewisAtomMapper(use_chirality)

Bases: schrodinger.comparison.atom_mapper.BaseAtomMapper

Used by comparison.py for comparison of conformers. Uses element types, formal charge, number of neighbors and total number of bonds to distinguish atoms. Optionally uses chirality to equate atoms

Usage example: mapper = LewisAtomMapper(use_chirality=False) st1, st2 = mapper.are_conformers(st1, range(1, st1.atom_total + 1), st2, range(st2.atom_total + 1))

__init__(use_chirality)
Parameters:use_chirality (boolean) – if True, in addition to element type use chirality (where defined) to equate atoms.
initialize_atom_types(st, invert_stereocenters=False)

Initialize the atom types

Parameters:
  • st (Structure) – structure containing atoms
  • invert_stereocenters (boolean) – whether or not R/S labels should be flipped
score_mapping(st1, st2, atset)

Score a mapping over the atoms in atset. This class is not intended for atom mapping problems but provide a score which is equal to the in place rmsd for testing purposes.

Parameters:
  • st1 (Structure) – first structure
  • st2 (Structure) – second structure
  • atset (set of ints) – set of atoms that have been mapped (indexes refer to both structures)
Returns:

an integer indicating the number of misaligned atom numbering stereocenters and a real representing the rmsd

score_is_equivalent(score1, score2)

determines if score should be considered equivalent

Parameters:
  • score1 (float) – the first score
  • score2 (float) – the second score
ATOM_TYPE = 's_m_custom_atom_type'
MAPPER_INDEX = 'i_m_atom_mapper_index'
are_conformers(st1, atlist1, st2, atlist2)

Determine if the two substructures, as defined by the atom lists, are conformers but do not explore isomorphisms.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

boolean indicating whether or not the two structures are conformers

are_enantiomers(st1, atlist1, st2, atlist2)

Determine if the two substructures, as defined by the atom lists, are enantiomers but do not explore isomorphisms.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

boolean indicating whether or not the two structures are conformers

comparator(d1, d2)

Comparison function to be used to determine if two nodes on graph are equivalent.

Parameters:
  • d1 (dict) – key=value dictionary from graph returned from st_to_graph which represents node 1
  • d1 – key=value dictionary from graph returned from st_to_graph which represents node 2
Returns:

boolean indicating equilvalence

get_atom_type(at)

This value is used as an atom property

Parameters:at (_StructureAtom) – atom we wish to obtain a type for
Returns:string which identifies atom type
invert_chirality(ch_list)

Invert the chirality (R/S) of an input list of chiralities.

Parameters:ch_list (list of strings) – list of chirality labels for a structure
isomeric_atom_sets(st1, atset1, st2, atset2)

Check that the atom types in atset1 are the same as those in atset2. If not, the two structures cannot be conformers.

Parameters:
  • st1 (Structure) – the first structure
  • atset1 (set of ints) – set of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atset2 (set of ints) – set of atom indexes defining the second substructure
Returns:

a boolean indicating if these atom lists are isomeric

reorder_structures(st1, atlist1, st2, atlist2, invert_stereocenters=False)

Reorder the atoms in the two structures.

Parameters:
  • st1 (Structure) – the first structure
  • atlist1 (list of ints) – list of atom indexes defining the first substructure
  • st2 (Structure) – the second structure
  • atlist2 (list of ints) – list of atom indexes defining the second substructure
Returns:

the two structures with structure 2 having had atoms reordered

set_atom_type(at, value)

Set the value of the atom type

Parameters:
  • at (_StructureAtom) – atom we wish to set type for
  • value (string) – set the type of atom to this
st_to_graph(st, atset)

Convert Structure instance to a networkx Graph using _StructureAtom instances as nodes and adding an atom type property

Parameters:
  • st (Structure) – the structure to convert
  • atset (set of ints) – a set of atoms to use to create the graph
Returns:

networkx Graph

unique_job_name(base_name)

Add an integer to the end of the base_name to get a unique name.

Parameters:base_name (str) – base job name