Molecule Graph

    Graphs offer a natural way of representing chemical structures. In this case the atoms are the nodes of the graph and the bonds are the edges. We can then “color” the nodes with atom types and “weigh” the edges with bond types. This graph, which contains nodes and edges with different properties, is the molecular graph.

    Elements of the molecule graph are:

    • atoms,

    • bonds.

    Only one connection/bond is allowed between any two atoms and no self connection is allowed. To represent this molecule graph in a computer the following matrices are introduced:

    • Connection table , ctab : the i- th row defines the indices of the atoms connected to the i- th atom.

      images/download/attachments/1806249/ctab.png Connection table (ctab):[2][1, 3, 4][2][2, 5][4]
    • Bond table , btab : bond indexes between atom i and atom j . For small molecules it is a square matrix, for large molecules a sparse matrix. It represents the following matrix:

      images/download/attachments/1806249/ctab.png Bond table (btab):[0, 1, 0, 0, 0][1, 0, 2, 3, 0][0, 2, 0, 0, 0][0, 3, 0, 0, 4][0, 0, 0, 4, 0]

    Please note that instead of getting the full bond table we are planning to introduce a new method that gives back the bond index between atoms i and j .

    Chemically relevant information in the graph:

    • number of connected fragments,

    • rings: SSSR (Smallest Set of Smallest Rings)

    Connections between the atoms specify the topology, but the relative spatial arrangement of atoms – the configuration – also needs to be defined, as molecules with same connectivity but different spatial arrangement – stereoisomers (see stereochemistry for details) – should be expressed.

    Spatial dimension of the building atoms defines the dimension of the molecule.

    • 0D – all atoms are in [0, 0, 0].

    • 2D – z coordinate is 0, [x, y, 0].

    • 3D – all coordinates are defined [x, y, z]

    The dimensionality can be retrieved by the getDim() method of MoleculeGraph class. It can be set by the setDim(int d) method, but setDim(int d) does not generate coordinates for the molecule. To generate coordinates, which is obviously needed (bear in mind that it can be a slow process), the clean(MoleculeGraph mg, int dim, java.lang.String opts) method of chemaxon.calculation.clean.Cleaner class can be used.

    Once the molecule is built the atom and bond indexes are fixed, they don't change with property changes (like changes in atom or bond type), but if the structure is modified with removal/addition of atoms or bonds, the indexes are changed.

    Please note, that atoms and bonds are indexed from 0, but MarvinView and MarvinSketch show the indexes starting from 1.

    Code examples

    Building molecule Ethylene

    
    /* 
     * Copyright (c) 1998-2022 Chemaxon Ltd. All Rights Reserved. 
     */
    import java.io.IOException;
    
    import chemaxon.formats.MolExporter;
    import chemaxon.calculations.clean.Cleaner;
    import chemaxon.struc.*; 
    
    /** 
     * Example class for structure manipulation. Creates ethylene C/C=C=/C atom by atom. 
     * 
     * @author Andras Volford, Miklos Vargyas  
     */ 
    public class BuildMoleculeEthyleneStereo { 
    
        public static void main(String[] args) throws IOException { 
            // create an empty Molecule 
            Molecule m = new Molecule(); 
    
            // create a Carbon atom 
            MolAtom a1 = new MolAtom(6); 
            // and add it to the molecule  
            m.add(a1); 
    
            // create anoter Carbon atom 
            MolAtom a2 = new MolAtom(6); 
            // and add it to the molecule 
            m.add(a2);     
    
            // create a bond between atoms, bond order  
            MolBond b = new MolBond(a1, a2, 2);         
            m.add(b);          
    
            System.out.println(MolExporter.exportToFormat(m, "smiles")); 
            // this prints C=C 
    
            // add ligands 
            MolAtom l1 = new MolAtom(6);         
            MolAtom l2 = new MolAtom(6);         
            m.add(l1);         
            m.add(l2);         
            m.add(new MolBond(a1, l1));         
            m.add(new MolBond(a2, l2)); 
    
            System.out.println(MolExporter.exportToFormat(m, "smiles"));
            System.out.println(MolExporter.exportToFormat(m, "mol"));          
            // generate 2D coordinates 
            Cleaner.clean(m, 2, null);       
            System.out.println(m.toFormat(MolExporter.exportToFormat(m, "mol")); 
        } 
    } 

    Building Ethylene with stereo information

    
    /* 
     * Copyright (c) 1998-2022 Chemaxon Ltd. All Rights Reserved. 
     */
    import java.io.IOException;
    
    import chemaxon.formats.MolExporter;
    import chemaxon.calculations.clean.Cleaner;
    import chemaxon.struc.*; 
    
    /** 
     * Example class for structure manipulation. Creates ethylene C/C=C=/C atom by atom. 
     * 
     * @author Andras Volford, Miklos Vargyas  
     */ 
    public class BuildMoleculeEthyleneStereo { 
        public static void main(String[] args) throws IOException{ 
            // create an empty Molecule 
            Molecule m = new Molecule(); 
    
            // create a Carbon atom 
            MolAtom a1 = new MolAtom(6); 
            // and add it to the molecule  
            m.add(a1); 
    
            // create another Carbon atom 
            MolAtom a2 = new MolAtom(6); 
            // and add it to the molecule 
            m.add(a2);     
    
            // create a bond between atoms, bond order  
            MolBond b = new MolBond(a1, a2, 2);         
            m.add(b);   
    
            System.out.println(MolExporter.exportToFormat(m,"smiles")); 
            // this prints C=C 
    
            // add ligands 
            MolAtom l1 = new MolAtom(6);         
            MolAtom l2 = new MolAtom(6);         
            m.add(l1);         
            m.add(l2);         
            m.add(new MolBond(a1, l1));         
            m.add(new MolBond(a2, l2));      
    
            System.out.println(MolExporter.exportToFormat(m,"smiles"));
            System.out.println(MolExporter.exportToFormat(m,"mol"));          
            // generate 2D coordinates 
            Cleaner.clean(m, 2, null);        
            System.out.println(MolExporter.exportToFormat(m, "mol"));          
    
            // CIS/TRANS information is not defined, the bond is wiggly 
            b = m.getBond(0); 
            System.out.println("cis=" + MolBond.CIS );
            System.out.println("trans=" + MolBond.TRANS );
            System.out.println("stereo flag before setting: " + (b.getFlags()  & MolBond.STEREO_MASK)); 
    
            // set bond to CIS 
            b.setFlags(MolBond.CIS, MolBond.STEREO_MASK);         
            System.out.println("stereo flag after setting: " + (b.getFlags()  & MolBond.STEREO_MASK)); 
            System.out.println(MolExporter.exportToFormat(m, "mol"));   
    
            // render again in 2D 
            System.out.println("Cleaned again");         
            Cleaner.clean(m, 2, null);        
            System.out.println("stereo flag: " + (b.getFlags() & MolBond.STEREO_MASK)); 
            System.out.println(MolExporter.exportToFormat(m, "mol")); 
    
            m.setDim(0);         
            b.setFlags(MolBond.CIS, MolBond.STEREO_MASK);         
            System.out.println("stereo flag after setting: " + (b.getFlags() & MolBond.STEREO_MASK)); 
            System.out.println(MolExporter.exportToFormat(m, "mol")); 
    
            // render again in 2D 
            System.out.println("Cleaned the 3rd time after setdim(0)");         
            Cleaner.clean(m, 2, null);        
            System.out.println("stereo flag: " + (b.getFlags() & MolBond.STEREO_MASK)); 
            System.out.println(MolExporter.exportToFormat(m, "mol"));     
        } 
    }