3.1.11.2. graph/Graph¶
3.1.11.2.1. Class Graph
¶
-
class
mod.
Graph
¶ This class models an undirected graph with labels on vertices and edges, without loops and without parallel edges. Certain labels are regarded as models of chemical atoms and bonds. See Molecule Encoding for more information on this.
-
vertices
¶ (Read-only) An iterable of all vertices in the graph.
- Type
GraphVertexRange
-
edges
¶ (Read-only) An iterable of all edges in the graph.
- Type
GraphEdgeRange
-
aut
(labelSettings=LabelSettings(LabelType.String, LabelRelation.Isomorphism))¶ - Parameters
labelSettings (LabelSettings) – the label settings to use.
- Returns
an object representing the automorphism group of the graph, with the given label settings.
- Return type
-
print
()¶ -
print
(first, second=None) Print the graph, using either the default options or the options in
first
andsecond
. Iffirst
andsecond
are the same, only one depiction will be made.- Parameters
first (GraphPrinter) – the printing options used for the first depiction.
second (GraphPrinter) – the printing options used for the second depiction. If it is
None
then it is set tofirst
.
- Returns
the names for the PDF-files that will be compiled in post-processing. If
first
andsecond
are the same, the two file prefixes are equal.- Return type
-
printTermState
()¶ Print the term state for the graph.
-
getGMLString
(withCoords=False)¶ - Returns
the GML representation of the graph, optionally with generated 2D coordinates.
- Return type
- Raises
LogicError
when coordinates are requested, but none can be generated.
-
printGML
(withCoords=False)¶ Print the GML representation of the graph, optionally with generated 2D coordinates.
- Returns
the filename of the printed GML file.
- Return type
- Raises
LogicError
when coordinates are requested, but none can be generated.
-
smiles
¶ (Read-only) If the graph models a molecule, this is the canonical SMILES string for it.
- Type
- Raises
LogicError
if the graph is not a molecule.
-
smilesWithIds
¶ (Read-only) If the graph models a molecule, this is the canonical SMILES string for it, that includes the internal vertex id as a class label on each atom.
- Type
- Raises
LogicError
if the graph is not a molecule.
-
graphDFSWithIds
¶ (Read-only) This is a GraphDFS of the graph, where each vertices have an explicit id, corresponding to its internal vertex id.
- Type
-
linearEncoding
¶ (Read-only) If the graph models a molecule this is the SMILES string string, otherwise it is the GraphDFS string.
- Type
-
isMolecule
¶ (Read-only) Whether or not the graph models a molecule. See Molecule Encoding.
- Type
-
energy
¶ (Read-only) If the graph models a molecule, this is some energy value. The energy is calculated using Open Babel, unless already calculated or cached by
Graph.cacheEnergy()
.- Type
-
cacheEnergy
(e)¶ If the graph models a molecule, sets the energy to a given value.
- Parameters
e (float) – the value for the energy to be set.
-
exactMass
¶ (Read-only) The exact mass of the graph, if it is a molecule. It is the sum of the exact mass of each atom, with the mass of electrons subtracted corresponding to the integer charge. That is, the mass is \(\sum_a (mass(a) - mass(e)\cdot charge(a))\). If an atom has no specified isotope, then the most abundant is used.
- Type
- Raises
LogicError
if it is not a molecule, including if some isotope has not been tabulated.
-
vLabelCount
(label)¶
-
eLabelCount
(label)¶
-
isomorphism
(other, maxNumMatches=1, labelSettings=LabelSettings(LabelType.String, LabelRelation.Isomorphism))¶ - Parameters
maxNumMatches (int) – the maximum number of isomorphisms to search for.
labelSettings (LabelSettings) – the label settings to use during the search.
- Returns
the number of isomorphisms from this graph to
other
, but at mostmaxNumMatches
.- Return type
-
monomorphism
(other, maxNumMatches=1, labelSettings=LabelSettings(LabelType.String, LabelRelation.Isomorphism))¶ - Parameters
maxNumMatches (int) – the maximum number of monomorphisms to search for.
labelSettings (LabelSettings) – the label settings to use during the search.
- Returns
the number of monomorphisms from this graph to
other
, though at mostmaxNumMatches
.- Return type
-
makePermutation
()¶ - Returns
a graph isomorphic to this, but with the vertex indices randomly permuted.
- Return type
-
image
¶ (Write-only) A custom depiction for the graph. The depiction file used will be the string returned by the given function, with
.pdf
appended. The function will only be called once.- Type
Callable[[], str]
-
imageCommad
¶ A command to be run in post-processing if a custom depiction is set. The command is only run once.
- Type
-
getVertexFromExternalId
(id)¶ If the graph was not loaded from an external data format, then this function always return a null descriptor. If the graph was loaded from a SMILES string, but any class label was not unique, then the function always return a null descriptor.
Note
In general there is no correlation between external and internal ids.
- Parameters
id (int) – the external id to find the vertex descriptor for.
- Returns
the vertex descriptor for the given external id. The descriptor is null if the external id was not used.
- Return type
-
minExternalId
¶ -
maxExternalId
¶ If the graph was not loaded from an external data format, then these attributes are always return 0. Otherwise, they are the minimum/maximum external id from which non-null vertices can be obtained from
getVertexFromExternalId()
. If no such minimum and maximum exists, then they are 0.- Type
-
instantiateStereo
()¶ Make sure that stereo data is instantiated.
- Raises
StereoDeductionError
if the data was not instantiated and deduction failed.
-
-
mod.
inputGraphs
¶ A list of graphs to which explicitly loaded graphs as default are appended.
-
mod.
graphGMLString
(s, name=None, add=True)¶ Load a graph in GML format from a given string.
- Parameters
name (str) – the name of the graph. If none is given the default name is used.
add (bool) – whether to append the graph to
inputGraphs
or not.
- Returns
the loaded graph.
- Return type
- Raises
InputError
on bad input.
-
mod.
graphGML
(f, name=None, add=True)¶ Load a graph in GML format from a given file.
- Parameters
name (str) – the name of the graph. If none is given the default name is used.
add (bool) – whether to append the graph to
inputGraphs
or not.
- Returns
the loaded graph.
- Return type
- Raises
InputError
on bad input.
-
mod.
graphDFS
(s, name=None, add=True)¶ Load a graph from a GraphDFS string.
- Parameters
name (str) – the name of the graph. If none is given the default name is used.
add (bool) – whether to append the graph to
inputGraphs
or not.
- Returns
the loaded graph.
- Return type
- Raises
InputError
on bad input.
-
mod.
smiles
(s, name=None, add=True, allowAbstract=False, classPolicy=SmilesClassPolicy.NoneOnDuplicate)¶ Load a molecule from a SMILES string.
- Parameters
- Returns
the loaded molecule.
- Return type
- Raises
InputError
on bad input.