Getting started#
This page provides a small overview of how to install MolFoundry in Python and how to run your first example scripts.
Install#
pip install --extra-index-url https://py.molfoundry.de/dl/ molfoundry
The wheel vendors the JavaScript compute engine, so there is nothing else to
install — no Node.js, no pythonmonkey.
In the rest of this documentation we assume MolFoundry to be imported as:
import molfoundry as mf
Building a molecule#
Molecules in MolFoundry are represented as graph structures and can be loaded from a variety of file and line formats such as GML, SMILES, or InChI. Optionally, a name can be provided to further identify the molecule.
water = mf.smiles("O", "water")
print("name: ", water.name)
print("SMILES: ", water.smiles)
print("vertices: ", water.numVertices, " edges:", water.numEdges)
print("is molecule:", water.isMolecule)
print("exact mass:", round(water.exactMass, 4))
print("InChI: ", water.inchi)
print("InChIKey: ", water.inchiKey)
name: water
SMILES: O
vertices: 3 edges: 2
is molecule: True
exact mass: 18.0106
InChI: InChI=1S/H2O/h1H2
InChIKey: XLYOFNOQVPJJNP-UHFFFAOYSA-N
water = mf.inchi("1S/H2O/h1H2", "water")
water = mf.molfile("""
MolFoundry 2D
0 0 0 0 0 0 999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 3 2 0 0 0
M V30 BEGIN ATOM
M V30 1 H 0 0 0 0
M V30 2 H 0 0 0 0
M V30 3 O 0 0 0 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 1 1 3
M V30 2 1 2 3
M V30 END BOND
M V30 END CTAB
M END""", "water")
water = mf.graphGMLString("""graph [
node [ id 1 label "H" ]
node [ id 2 label "H" ]
node [ id 3 label "O" ]
edge [ source 1 target 3 label "-" ]
edge [ source 2 target 3 label "-" ]
]""", "water")
Look inside the graph#
A molecule is a labeled graph. Count vertex/edge labels and inspect its symmetry (the automorphism group).
co2 = mf.smiles("O=C=O", "carbon dioxide")
print("carbons: ", co2.vLabelCount("C"))
print("oxygens: ", co2.vLabelCount("O"))
print("double bonds: ", co2.eLabelCount("="))
print("automorphisms:", co2.aut())
carbons: 1
oxygens: 2
double bonds: 2
automorphisms: [(), (0 1)]
The two oxygens are interchangeable, so the automorphism group is non-trivial —
co2.aut() reports the swap.
Serialize#
Every graph round-trips through GML, which is also molfoundry’s native format for hand-written graphs and rules.
print(co2.getGMLString())
graph [
node [ id 0 label "O" ]
node [ id 1 label "O" ]
node [ id 2 label "C" ]
edge [ source 0 target 2 label "=" ]
edge [ source 1 target 2 label "=" ]
]
Where to go next#
The API reference documents every public class and function.
The MolFoundry by Examples guide.