rmgpy.molecule.Group

class rmgpy.molecule.Group(atoms=None, props=None, multiplicity=None)

A representation of a molecular substructure group using a graph data type, extending the Graph class. The attributes are:

Attribute Type Description
atoms list Aliases for the vertices storing GroupAtom
multiplicity list Range of multiplicities accepted for the group
props dict Dictionary of arbitrary properties/flags classifying state of Group object

Corresponding alias methods to Molecule have also been provided.

addAtom(self, GroupAtom atom)

Add an atom to the graph. The atom is initialized with no bonds.

addBond(self, GroupBond bond)

Add a bond to the graph as an edge connecting the two atoms atom1 and atom2.

addEdge(self, Edge edge) → Edge

Add an edge to the graph. The two vertices in the edge must already exist in the graph, or a ValueError is raised.

addExplicitLigands(self) → bool

This function Od/Sd ligand to CO or CS atomtypes if they are not already there.

Returns a ‘True’ if the group was modified otherwise returns ‘False’

addImplicitAtomsFromAtomType(self) → Group

Returns: a modified group with implicit atoms added Add implicit double/triple bonded atoms O, S or R, for which we will use a C

Not designed to work with wildcards

addImplicitBenzene(self) → Group

Returns: A modified group with any implicit benzene rings added

This method currently does not if there are wildcards in atomtypes or bond orders The current algorithm also requires that all Cb and Cbf are atomtyped

There are other cases where the algorithm doesn’t work. For example whenever there are many dangling Cb or Cbf atoms not in a ring, it is likely fail. In the database test (the only use thus far), we will require that any group with more than 3 Cbfs have complete rings. This is much stricter than this method can handle, but right now this method cannot handle very general cases, so it is better to be conservative.

addVertex(self, Vertex vertex) → Vertex

Add a vertex to the graph. The vertex is initialized with no edges.

atoms

Group.__getAtoms(self)

carbonCount

carbonCount: ‘short’

classifyBenzeneCarbons(self, dict partners=None) → tuple
Args:
group: :class:Group with atoms to classify partners: dictionary of partnered up atoms, which must be a cbf atom

Returns: tuple with lists of each atom classification

clearLabeledAtoms(self)

Remove the labels from all atoms in the molecular group.

containsLabeledAtom(self, str label) → bool

Return True if the group contains an atom with the label label and False otherwise.

copy(self, bool deep=False) → Graph

Create a copy of the current graph. If deep is True, a deep copy is made: copies of the vertices and edges are used in the new graph. If deep is False or not specified, a shallow copy is made: the original vertices and edges are used in the new graph.

copyAndMap(self) → dict

Create a deep copy of the current graph, and return the dict ‘mapping’. Method was modified from Graph.copy() method

createAndConnectAtom(self, list atomtypes, GroupAtom connectingAtom, list bondOrders) → GroupAtom

This method creates an non-radical, uncharged, :class:GroupAtom with specified list of atomtypes and connects it to one atom of the group, ‘connectingAtom’. This is useful for making sample atoms.

Args:
atomtypes: list of atomtype labels (strs) connectingAtom: :class:GroupAtom that is connected to the new benzene atom bondOrders: list of bond Orders connecting newAtom and connectingAtom

Returns: the newly created atom

draw(self, format)

Use pydot to draw a basic graph of the group.

Use format to specify the desired output format, eg. ‘png’, ‘svg’, ‘ps’, ‘pdf’, ‘plain’, etc.

findIsomorphism(self, Graph other, dict initialMap=None) → list

Returns True if other is isomorphic and False otherwise, and the matching mapping. The initialMap attribute can be used to specify a required mapping from self to other (i.e. the atoms of self are the keys, while the atoms of other are the values). The returned mapping also uses the atoms of self for the keys and the atoms of other for the values. The other parameter must be a Group object, or a TypeError is raised.

findSubgraphIsomorphisms(self, Graph other, dict initialMap=None) → list

Returns True if other is subgraph isomorphic and False otherwise. In other words, return True is self is more specific than other. Also returns the lists all of valid mappings. The initialMap attribute can be used to specify a required mapping from self to other (i.e. the atoms of self are the keys, while the atoms of other are the values). The returned mappings also use the atoms of self for the keys and the atoms of other for the values. The other parameter must be a Group object, or a TypeError is raised.

fromAdjacencyList(self, str adjlist)

Convert a string adjacency list adjlist to a molecular structure. Skips the first line (assuming it’s a label) unless withLabel is False.

getAllCycles(self, Vertex startingVertex) → list

Given a starting vertex, returns a list of all the cycles containing that vertex.

This function returns a duplicate of each cycle because [0,1,2,3] is counted as separate from [0,3,2,1]

getAllCyclesOfSize(self, int size) → list

Return a list of the all non-duplicate rings with length ‘size’. The algorithm implements was adapted from a description by Fan, Panaye, Doucet, and Barbu (doi: 10.1021/ci00015a002)

B. T. Fan, A. Panaye, J. P. Doucet, and A. Barbu. “Ring Perception: A New Algorithm for Directly Finding the Smallest Set of Smallest Rings from a Connection Table.” J. Chem. Inf. Comput. Sci. 33, p. 657-662 (1993).

getAllCyclicVertices(self) → list

Returns all vertices belonging to one or more cycles.

getAllPolycyclicVertices(self) → list

Return all vertices belonging to two or more cycles, fused or spirocyclic.

getAllSimpleCyclesOfSize(self, int size) → list

Return a list of all non-duplicate monocyclic rings with length ‘size’.

Naive approach by eliminating polycyclic rings that are returned by getAllCyclicsOfSize.

getBond(self, GroupAtom atom1, GroupAtom atom2) → GroupBond

Returns the bond connecting atoms atom1 and atom2.

getBonds(self, GroupAtom atom) → dict

Return a list of the bonds involving the specified atom.

getDisparateRings(self) → tuple

Return a list of distinct polycyclic and monocyclic rings within the graph. There is some code duplication in this function in order to maximize speed up so as to call self.getSmallestSetOfSmallestRings() only once.

Returns: monocyclicRingsList, polycyclicRingsList

getEdge(self, Vertex vertex1, Vertex vertex2) → Edge

Returns the edge connecting vertices vertex1 and vertex2.

getEdges(self, Vertex vertex) → dict

Return a dictionary of the edges involving the specified vertex.

getLabeledAtom(self, str label) → GroupAtom

Return the atom in the group that is labeled with the given label. Raises ValueError if no atom in the group has that label.

getLabeledAtoms(self) → dict

Return the labeled atoms as a dict with the keys being the labels and the values the atoms themselves. If two or more atoms have the same label, the value is converted to a list of these atoms.

getLargestRing(self, Vertex vertex) → list

returns the largest ring containing vertex. This is typically useful for finding the longest path in a polycyclic ring, since the polycyclic rings returned from getPolycyclicRings are not necessarily in order in the ring structure.

getMonocyclicRings(self) → list

Return a list of cycles that are monocyclic.

getPolycyclicRings(self) → list

Return a list of cycles that are polycyclic. In other words, merge the cycles which are fused or spirocyclic into a single polycyclic cycle, and return only those cycles. Cycles which are not polycyclic are not returned.

getSmallestSetOfSmallestRings(self) → list

Return a list of the smallest set of smallest rings in the graph. The algorithm implements was adapted from a description by Fan, Panaye, Doucet, and Barbu (doi: 10.1021/ci00015a002)

B. T. Fan, A. Panaye, J. P. Doucet, and A. Barbu. “Ring Perception: A New Algorithm for Directly Finding the Smallest Set of Smallest Rings from a Connection Table.” J. Chem. Inf. Comput. Sci. 33, p. 657-662 (1993).

hasAtom(self, GroupAtom atom) → bool

Returns True if atom is an atom in the graph, or False if not.

hasBond(self, GroupAtom atom1, GroupAtom atom2) → bool

Returns True if atoms atom1 and atom2 are connected by an bond, or False if not.

hasEdge(self, Vertex vertex1, Vertex vertex2) → bool

Returns True if vertices vertex1 and vertex2 are connected by an edge, or False if not.

hasVertex(self, Vertex vertex) → bool

Returns True if vertex is a vertex in the graph, or False if not.

isAromaticRing(self) → bool

This method returns a boolean telling if the group has a 5 or 6 cyclic with benzene bonds exclusively

isBenzeneExplicit(self) → bool

Returns: ‘True’ if all Cb, Cbf atoms are in completely explicitly stated benzene rings.

Otherwise return ‘False’

isCyclic(self) → bool

Return True if one or more cycles are present in the graph or False otherwise.

isEdgeInCycle(self, Edge edge) → bool

Return True if the edge between vertices vertex1 and vertex2 is in one or more cycles in the graph, or False if not.

isIdentical(self, Graph other) → bool

Returns True if other is identical and False otherwise. The function isIsomorphic respects wildcards, while this function does not, make it more useful for checking groups to groups (as opposed to molecules to groups)

isIsomorphic(self, Graph other, dict initialMap=None) → bool

Returns True if two graphs are isomorphic and False otherwise. The initialMap attribute can be used to specify a required mapping from self to other (i.e. the atoms of self are the keys, while the atoms of other are the values). The other parameter must be a Group object, or a TypeError is raised.

isMappingValid(self, Graph other, dict mapping) → bool

Check that a proposed mapping of vertices from self to other is valid by checking that the vertices and edges involved in the mapping are mutually equivalent.

isSubgraphIsomorphic(self, Graph other, dict initialMap=None) → bool

Returns True if other is subgraph isomorphic and False otherwise. In other words, return True if self is more specific than other. The initialMap attribute can be used to specify a required mapping from self to other (i.e. the atoms of self are the keys, while the atoms of other are the values). The other parameter must be a Group object, or a TypeError is raised.

isVertexInCycle(self, Vertex vertex) → bool

Return True if the given vertex is contained in one or more cycles in the graph, or False if not.

makeSampleMolecule(self) → Molecule

Returns: A sample class :Molecule: from the group

merge(self, Graph other) → Graph

Merge two groups so as to store them in a single Group object. The merged Group object is returned.

mergeGroups(self, Group other) → Group

This function takes other :class:Group object and returns a merged :class:Group object based on overlapping labeled atoms between self and other

Currently assumes other can be merged at the closest labelled atom

multiplicity

multiplicity: list

nitrogenCount

nitrogenCount: ‘short’

oxygenCount

oxygenCount: ‘short’

pickWildcards(self)

Returns: the :class:Group object without wildcards in either atomtype or bonding

This function will naively pick the first atomtype for each atom, but will try to pick bond orders that make sense given the selected atomtypes

props

props: dict

radicalCount

radicalCount: ‘short’

removeAtom(self, GroupAtom atom)

Remove atom and all bonds associated with it from the graph. Does not remove atoms that no longer have any bonds as a result of this removal.

removeBond(self, GroupBond bond)

Remove the bond between atoms atom1 and atom2 from the graph. Does not remove atoms that no longer have any bonds as a result of this removal.

removeEdge(self, Edge edge)

Remove the specified edge from the graph. Does not remove vertices that no longer have any edges as a result of this removal.

removeVertex(self, Vertex vertex)

Remove vertex and all edges associated with it from the graph. Does not remove vertices that no longer have any edges as a result of this removal.

resetConnectivityValues(self)

Reset any cached connectivity information. Call this method when you have modified the graph.

sortAtoms(self)

Sort the atoms in the graph. This can make certain operations, e.g. the isomorphism functions, much more efficient.

sortByConnectivity(self, list atomList) → list
Args:
atomList: input list of atoms

Returns: a sorted list of atoms where each atom is connected to a previous atom in the list if possible

sortVertices(self)

Sort the vertices in the graph. This can make certain operations, e.g. the isomorphism functions, much more efficient.

split(self) → list

Convert a single Group object containing two or more unconnected groups into separate class:Group objects.

standardizeAtomType(self) → bool

This function changes the atomTypes in a group if the atom must be a specific atomType based on its bonds and valency.

Currently only standardizes oxygen, carbon and sulfur atomTypes

We also only check when there is exactly one atomType, one bondType, one radical setting. For any group where there are wildcards or multiple attributes, we cannot apply this check.

In the case where the atomType is ambigious based on bonds and valency, this function will not change the type.

Returns a ‘True’ if the group was modified otherwise returns ‘False’

standardizeGroup(self) → bool

This function modifies groups to make them have a standard AdjList form.

Currently it makes atomtypes as specific as possible and makes CO/CS atomtypes have explicit Od/Sd ligands. Other functions can be added as necessary

Returns a ‘True’ if the group was modified otherwise returns ‘False’

sulfurCount

sulfurCount: ‘short’

toAdjacencyList(self, str label='')

Convert the molecular structure to a string adjacency list.

update(self)
updateConnectivityValues(self)

Update the connectivity values for each vertex in the graph. These are used to accelerate the isomorphism checking.

updateFingerprint(self)

Update the molecular fingerprint used to accelerate the subgraph isomorphism checks.

vertices

vertices: list