Search in sources :

Example 21 with IMolecule

use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.

the class MySmilesTests method oxydoAromaticTest.

@Test
public void oxydoAromaticTest() {
    String smiles = "c1ccccc1O";
    String result = "O(c(c(c(c(c[1]))))(c[1]))";
    IMolecule mol = null;
    try {
        mol = SmilesConverter.conv.transform(smiles);
    } catch (InvalidSmilesException e) {
        e.printStackTrace();
    }
    Assert.assertEquals(result, this.ms.convert(mol, false));
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) Test(org.junit.Test)

Example 22 with IMolecule

use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.

the class MySmilesTests method doubleLinkTest.

@Test
public void doubleLinkTest() {
    String smiles = "CC(=O)O";
    String result = "C(=O)(C)(O)";
    IMolecule mol = null;
    try {
        mol = SmilesConverter.conv.transform(smiles);
    } catch (InvalidSmilesException e) {
        e.printStackTrace();
    }
    Assert.assertEquals(result, this.ms.convert(mol, false));
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) Test(org.junit.Test)

Example 23 with IMolecule

use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.

the class HydrogenAdd method getFreeHydrogens.

/**
 * Transform mc parameter to correct parameters for arity calculation
 * @param mc
 * @return
 */
private int getFreeHydrogens(MappedChain mc) {
    int atomIdx = mc.getAtomsMapping().get(this.idx);
    IMolecule mol = mc.getChemObject().getMolecule();
    IAtom a = mol.getAtom(atomIdx);
    int mappedHydrogens = mc.getHydrogensMapping().get(atomIdx);
    int presentHydrogens = a.getImplicitHydrogenCount();
    return presentHydrogens - mappedHydrogens;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 24 with IMolecule

use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.

the class IsomorphismFamilyMatcher method matchFamilly.

@Override
public Coverage matchFamilly(Family family) {
    // Initialization
    Coverage cov = new Coverage(co);
    IMolecule mol = co.getMolecule();
    Set<Residue> markSet = new HashSet<>();
    Stack<Residue> searchSet = new Stack<>();
    searchSet.addAll(family.getRoots());
    // For all the nodes in the search group.
    while (!searchSet.isEmpty()) {
        Residue currentRes = searchSet.pop();
        // Search the current residue in mol.
        try {
            this.sqt.setSmarts(currentRes.getSmiles());
        } catch (CDKException e) {
            e.printStackTrace();
        }
        boolean isMatching = false;
        try {
            long time = System.currentTimeMillis();
            isMatching = this.sqt.matches(mol);
            if (verbose)
                System.out.println("    Search for " + currentRes.getName() + " in " + (System.currentTimeMillis() - time));
        } catch (CDKException e) {
            e.printStackTrace();
        }
        // If there is at least one occurrence.
        if (isMatching) {
            // Add matches to the coverage
            List<Match> matches = new ArrayList<>();
            for (List<Integer> lMatch : sqt.getMatchingAtoms()) {
                Match match = new Match(currentRes);
                for (int i : lMatch) match.addAtom(i);
                matches.add(match);
            }
            // Change to compare.
            cov.addListMatches(currentRes, matches);
            // Mark current residue to possibly add children.
            markSet.add(currentRes);
            // Add children with all parents marked
            Set<Residue> children = family.getChildrenOf(currentRes);
            for (Residue child : children) {
                boolean canBeAdded = true;
                for (Link dependance : family.getDepandances()) if (dependance.getTo().equals(child))
                    if (!markSet.contains(dependance.getFrom())) {
                        canBeAdded = false;
                        break;
                    }
                if (canBeAdded)
                    searchSet.add(child);
            }
        }
    }
    return cov;
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) ArrayList(java.util.ArrayList) Coverage(algorithms.utils.Coverage) Stack(java.util.Stack) Match(algorithms.utils.Match) IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) Link(model.Family.Link) HashSet(java.util.HashSet)

Example 25 with IMolecule

use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.

the class Chain method getMolecule.

/**
 * construct recursively a molecule corresponding to the bloc.
 * Attention, this function is not very efficient because of multiple molecules creation.
 * @return Bloc molecule. Can return null if there are problems of compatibility between sub-bloc and extension positions.
 */
public IMolecule getMolecule() {
    if (this.mol != null)
        return this.mol;
    IMolecule mol = null;
    this.atoms = new ArrayList<>();
    // Sub-bloc molecule
    if (this.getSize() > 1) {
        IMolecule subMol = this.subBlc.getMolecule();
        mol = new Molecule();
        for (IAtom a : subMol.atoms()) mol.addAtom(a);
        for (IBond b : subMol.bonds()) mol.addBond(b);
        for (IAtom a : this.subBlc.atoms) {
            IAtom cloneA = mol.getAtom(subMol.getAtomNumber(a));
            this.atoms.add(cloneA);
        }
    } else {
        mol = new Molecule();
    }
    // Extension of mol
    IAtom a1 = this.ext.getBond().getAtom(0);
    if (this.position1 == -1) {
        try {
            a1 = (IAtom) a1.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        mol.addAtom(a1);
        this.atoms.add(a1);
        // Hydrogens
        int hydrogens = this.ext.getBond().getAtom(0).getImplicitHydrogenCount();
        a1.setImplicitHydrogenCount(hydrogens);
        // Aromatic
        if (this.ext.getBond().getAtom(0).getFlag(CDKConstants.ISAROMATIC))
            a1.setFlag(CDKConstants.ISAROMATIC, true);
        else
            a1.setFlag(CDKConstants.ISAROMATIC, false);
    } else {
        if (a1.getAtomicNumber() == this.atoms.get(this.position1).getAtomicNumber())
            a1 = this.atoms.get(this.position1);
        else
            return null;
    }
    IAtom a2 = this.ext.getBond().getAtom(1);
    if (this.position2 == -1) {
        try {
            a2 = (IAtom) a2.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        mol.addAtom(a2);
        this.atoms.add(a2);
        // Hydrogen
        int hydrogens = this.ext.getBond().getAtom(1).getImplicitHydrogenCount();
        a2.setImplicitHydrogenCount(hydrogens);
        // Aromatic
        if (this.ext.getBond().getAtom(1).getFlag(CDKConstants.ISAROMATIC))
            a2.setFlag(CDKConstants.ISAROMATIC, true);
        else
            a2.setFlag(CDKConstants.ISAROMATIC, false);
    } else if (a2.getAtomicNumber() == this.atoms.get(this.position2).getAtomicNumber())
        a2 = this.atoms.get(this.position2);
    else
        return null;
    mol.addBond(new Bond(a1, a2, this.ext.getBond().getOrder()));
    this.mol = mol;
    return mol;
}
Also used : Molecule(org.openscience.cdk.Molecule) IMolecule(org.openscience.cdk.interfaces.IMolecule) IMolecule(org.openscience.cdk.interfaces.IMolecule) IBond(org.openscience.cdk.interfaces.IBond) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

IMolecule (org.openscience.cdk.interfaces.IMolecule)28 IAtom (org.openscience.cdk.interfaces.IAtom)12 ArrayList (java.util.ArrayList)7 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)7 Residue (model.Residue)6 IBond (org.openscience.cdk.interfaces.IBond)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 CDKException (org.openscience.cdk.exception.CDKException)5 MappedChain (algorithms.isomorphism.chains.MappedChain)4 Match (algorithms.utils.Match)4 HashMap (java.util.HashMap)4 Rule (model.Rule)3 JSONObject (org.json.simple.JSONObject)3 Chain (algorithms.isomorphism.chains.Chain)2 BondMapping (algorithms.isomorphism.chains.Extension.BondMapping)2 MonomersDB (db.MonomersDB)2 PolymersDB (db.PolymersDB)2 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)2 IOException (java.io.IOException)2