Implementation

    The core representation of R-group structures is the chemaxon.struc.RgMolecule class.

    Build a Markush-structure

    The core of the root molecule ( i.e. the molecule without the R-atoms) can be built in a same way as any other MoleculeGraph object. To create an R-atom, use the MolAtom.RGROUPconstant in the constructor of the MolAtom. Using the MolAtom.setRgroup(int), an ID can be set for the R-atom. Note, that R-atoms are MolAtom objects, hence they should be added to the root molecule. Create R-atoms and a root molecule

    
    MolAtom r1 = new MolAtom(MolAtom.RGROUP);
    r1.setRgroup(1);

    An RgMolecule object can be constructed with an empty constructor. Specify its root molecule using the RgMolecule.setRoot(MoleculeGraph)method. Create R-group

    
    RgMolecule rgMol = new RgMolecule();
    rgMol.setRoot(root);

    R-group definitions are Molecule objects. To define an R-group attachment point to one of its atoms use the MolAtom.addRgroupAttachmentPoint(int, int). With the first integer the order of the attachment point is set, the second one defines the bond type. R-group definition should be added to the corresponding R-group using the RgMolecule.addRgroup(int, Molecule). The integer parameter shows to which R-atom the definition corresponds to. Create R-group definition

    
    Molecule rg = MolImporter.importMol("O");
    rg.getAtom(0).addRgroupAttachmentPoint(1, 1);
    rgMol.addRgroup(1, rg);

    Full example of building a Markush-structure

    
    /*
     *  Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
     *  This software is the confidential and proprietary information of
     *  ChemAxon. You shall not disclose such Confidential Information
     *  and shall use it only in accordance with the terms of the agreements
     *  you entered into with ChemAxon.
     *  
     */
    package chemaxon.examples.strucrep;
     
    import java.io.IOException;
     
    import chemaxon.calculations.clean.Cleaner;
    import chemaxon.formats.MolExporter;
    import chemaxon.formats.MolImporter;
    import chemaxon.struc.MolAtom;
    import chemaxon.struc.MolBond;
    import chemaxon.struc.Molecule;
    import chemaxon.struc.RgMolecule;
     
    /**
     * Example class. Creates a basic RgMolecule.
     * 
     * @author Janos Kendi
     * 
     */
    public class BuildRgMolecule {
     
        public static void main(String[] args) throws IOException {
     
            // Create the root of the RgMolecule
            Molecule root = MolImporter.importMol("C1CCCCC1");
     
            // Create Rgroups
            MolAtom r1 = new MolAtom(MolAtom.RGROUP);
            r1.setRgroup(1);
            root.add(r1);
            root.add(new MolBond(r1, root.getAtom(0)));
     
            MolAtom r2 = new MolAtom(MolAtom.RGROUP);
            r2.setRgroup(2);
            root.add(r2);
            root.add(new MolBond(r2, root.getAtom(5)));
     
            // Create the RgMolecule
            RgMolecule rgMol = new RgMolecule();
            rgMol.setRoot(root);
     
            // Add Rgroup definitions
            Molecule rg = MolImporter.importMol("O");
            rg.getAtom(0).addRgroupAttachmentPoint(1, 1);
            rgMol.addRgroup(1, rg);
     
            rg = MolImporter.importMol("N");
            rg.getAtom(0).addRgroupAttachmentPoint(1, 2);
            rgMol.addRgroup(1, rg);
     
            rg = MolImporter.importMol("CC");
            rg.getAtom(0).addRgroupAttachmentPoint(1, 1);
            rgMol.addRgroup(2, rg);
     
            Cleaner.clean(rgMol, 2, null);
     
            System.out.println(MolExporter.exportToFormat(rgMol, "mrv:P"));
        }
     
    }

    Accessing the elements of a Markush-structure

    The root structure can be accessed by calling RgMolecule.getRoot()method, the R-group members can be retrieved by calling RgMolecule.getRgroupMember(int, int). Access the root molecule and the R-group definition

    
    //get the root structure and enumerate the atoms, find R-Atoms.
    Molecule root = rgmol.getRoot();
    for (int i = root.getAtomCount() - 1; i >= 0; --i){
        MolAtom atom = root.getAtom(i);
        if (atom.getAtno() == MolAtom.RGROUP){
           ....
        }
    }
    
    //enumerate the R-group definitions and its fragments
    int nr = rgmol.getRgroupCount();
    for(int i = 0; i < nr; ++i) {
        int nrm = rgmol.getRgroupMemberCount(i);
        for(int j = 0; j < nrm; ++j) {
            // .... do something with rgmol.getRgroupMember(i, j) 
        }
    }