# 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 O2d/S2d 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)

classifyBenzeneCarbons(self, dict partners=None) → tuple
Parameters: 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.

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

elementCount

elementCount – dict

findIsomorphism(self, Graph other, dict initialMap=None, bool saveOrder=False) → 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, bool saveOrder=False) → 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.

getAllEdges(self) → list

Returns a list of all edges in the graph.

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

Get all disjoint monocyclic and polycyclic cycle clusters in the molecule. Takes the RC and recursively merges all cycles which share vertices.

Returns: monocyclic_cycles, polycyclic_cycles

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.

getExtensions(self, R=None, basename='', atmInd=None, atmInd2=None)

generate all allowed group extensions and their complements note all atomtypes except for elements and R/R!H’s must be removed

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.

getNetCharge(self)

Iterate through the atoms in the group and calculate the net charge

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.

getRelevantCycles(self) → list

Returns the set of relevant cycles as a list of lists. Uses RingDecomposerLib for ring perception.

Kolodzik, A.; Urbaczek, S.; Rarey, M. Unique Ring Families: A Chemically Meaningful Description of Molecular Ring Topologies. J. Chem. Inf. Model., 2012, 52 (8), pp 2013-2021

Flachsenberg, F.; Andresen, N.; Rarey, M. RingDecomposerLib: An Open-Source Implementation of Unique Ring Families and Other Cycle Bases. J. Chem. Inf. Model., 2017, 57 (2), pp 122-126

getSmallestSetOfSmallestRings(self) → list

Returns the smallest set of smallest rings as a list of lists. Uses RingDecomposerLib for ring perception.

Kolodzik, A.; Urbaczek, S.; Rarey, M. Unique Ring Families: A Chemically Meaningful Description of Molecular Ring Topologies. J. Chem. Inf. Model., 2012, 52 (8), pp 2013-2021

Flachsenberg, F.; Andresen, N.; Rarey, M. RingDecomposerLib: An Open-Source Implementation of Unique Ring Families and Other Cycle Bases. J. Chem. Inf. Model., 2017, 57 (2), pp 122-126

get_element_count(self) → dict

Returns the element count for the molecule as a dictionary. Wildcards are not counted as any particular element.

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 saveOrder=False) → 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 saveOrder=False) → 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 equivalent=True) → 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. If equivalent is true it checks if atoms and edges are equivalent, if false it checks if they are specific cases of each other.

isSubgraphIsomorphic(self, Graph other, dict initialMap=None, bool generateInitialMap=False, bool saveOrder=False) → 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

ordered_vertices

ordered_vertices – list

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

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.

resetRingMembership(self)

Resets ring membership information in the GroupAtom.props attribute.

restore_vertex_order(self)

reorder the vertices to what they were before sorting if you saved the order

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
Parameters: 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, bool saveOrder=False)

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

specifyAtomExtensions(self, i, basename, R)

generates extensions for specification of the type of atom defined by a given atomtype or set of atomtypes

specifyBondExtensions(self, i, j, basename, Rbonds)

generates extensions for the specification of bond order for a given bond

specifyExternalNewBondExtensions(self, i, basename, Rbonds)

generates extensions for the creation of a bond (of undefined order) between an atom and a new atom that is not H

specifyInternalNewBondExtensions(self, i, j, Nsplits, basename, Rbonds)

generates extensions for creation of a bond (of undefined order) between two atoms indexed i,j that already exist in the group and are unbonded

specifyUnpairedExtensions(self, i, basename, Run)

generates extensions for specification of the number of electrons on a given atom

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 O2d/S2d ligands. Other functions can be added as necessary

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

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.

update_charge(self)

Update the partial charge according to the valence electron, total bond order, lone pairs and radical electrons. This method is used for products of specific families with recipes that modify charges.

vertices

vertices – list