rmgpy.molecule.Group

class rmgpy.molecule.Group

A representation of a molecular substructure group using a graph data type, extending the Graph class. The atoms and bonds attributes are aliases for the vertices and edges attributes, and store GroupAtom and GroupBond objects, respectively. Corresponding alias methods have also been provided.

addAtom()

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

addBond()

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

addEdge()

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

addExplicitLigands()

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

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

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

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

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

Remove the labels from all atoms in the molecular group.

containsLabeledAtom()

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

copy()

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.

createAndConnectAtom()

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

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

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

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

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

getAllCycles()

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

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

Returns all vertices belonging to one or more cycles.

getAllPolycyclicVertices()

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

getBond()

Returns the bond connecting atoms atom1 and atom2.

getBonds()

Return a list of the bonds involving the specified atom.

getDisparateRings()

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

Returns the edge connecting vertices vertex1 and vertex2.

getEdges()

Return a list of the edges involving the specified vertex.

getLabeledAtom()

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

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.

getMonocyclicRings()

Return a list of cycles that are monocyclic.

getPolycyclicRings()

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

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

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

hasBond()

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

hasEdge()

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

hasVertex()

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

isAromaticRing()

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

isBenzeneExplicit()

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

Otherwise return ‘False’

isCyclic()

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

isEdgeInCycle()

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

isIdentical()

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

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

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

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

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

makeSampleMolecule()

Returns: A sample class :Molecule: from the group

merge()

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

removeAtom()

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

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

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

removeVertex()

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

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

sortAtoms()

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

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

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

split()

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

standardizeAtomType()

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

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’

toAdjacencyList()

Convert the molecular structure to a string adjacency list.

updateConnectivityValues()

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

updateFingerprint()

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