Search in sources :

Example 31 with IAtom

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

the class SmilesConverter method transform.

public Molecule transform(String smiles, boolean addHydrogens, boolean calculateCoordinate, boolean expliciteHydrogens) throws InvalidSmilesException {
    Molecule imol = null;
    try {
        imol = new Molecule(sp.parseSmiles(smiles));
        // Add hydrogens
        if (addHydrogens) {
            CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(imol.getBuilder());
            try {
                adder.addImplicitHydrogens(imol);
                if (expliciteHydrogens)
                    AtomContainerManipulator.convertImplicitToExplicitHydrogens(imol);
            } catch (CDKException e) {
                e.printStackTrace();
            }
        } else {
            for (IAtom a : imol.atoms()) a.setImplicitHydrogenCount(0);
            if (!expliciteHydrogens)
                imol = new Molecule(AtomContainerManipulator.removeHydrogens(imol));
        }
        if (calculateCoordinate) {
            StructureDiagramGenerator sdg = new StructureDiagramGenerator(imol);
            try {
                sdg.generateCoordinates();
            } catch (CDKException e) {
                System.err.println(smiles);
                e.printStackTrace();
            }
            imol = new Molecule(sdg.getMolecule());
        }
    } catch (InvalidSmilesException e) {
        throw e;
    }
    return imol;
}
Also used : Molecule(org.openscience.cdk.Molecule) IMolecule(org.openscience.cdk.interfaces.IMolecule) CDKException(org.openscience.cdk.exception.CDKException) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) IAtom(org.openscience.cdk.interfaces.IAtom) StructureDiagramGenerator(org.openscience.cdk.layout.StructureDiagramGenerator)

Example 32 with IAtom

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

the class Coverage method getCoverageRatio.

public double getCoverageRatio() {
    if (!this.alreadyCalculate)
        this.calculateGreedyCoverage();
    int coveredAtoms = 0;
    for (Match match : this.usedMatches) coveredAtoms += match.getAtoms().size();
    int pepAtoms = 0;
    for (@SuppressWarnings("unused") IAtom a : this.co.getMolecule().atoms()) pepAtoms++;
    double ratio = new Double(coveredAtoms) / new Double(pepAtoms);
    return ratio;
}
Also used : IAtom(org.openscience.cdk.interfaces.IAtom)

Example 33 with IAtom

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

the class IsomorphismTests method MappingTest.

@Test
public void MappingTest() {
    List<MappedChain> mbs = Isomorphism.searchFromPreviousMapping(this.mb0, this.ext1, MatchingType.STRONG);
    boolean isGood = true;
    for (MappedChain mb : mbs) {
        List<MappedChain> extendedMbs = Isomorphism.searchFromPreviousMapping(mb, this.ext2, MatchingType.STRONG);
        MappedChain newMb = extendedMbs.get(0);
        IMolecule mol = mb.getChemObject().getMolecule();
        IAtom newA = (mol.getAtom(newMb.getAtomsMapping().get(2)));
        if (!(// Same first atom
        (newMb.getAtomsMapping().get(0) == mb.getAtomsMapping().get(0)) && // Same second atom
        (newMb.getAtomsMapping().get(1) == mb.getAtomsMapping().get(1)) && // Extended by C atom
        (newA.getSymbol().equals("C"))))
            isGood = false;
    }
    Assert.assertTrue(isGood);
}
Also used : MappedChain(algorithms.isomorphism.chains.MappedChain) IMolecule(org.openscience.cdk.interfaces.IMolecule) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test)

Example 34 with IAtom

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

the class ContractedGraph method addUncoveredVerticies.

// Create nodes not covered
private void addUncoveredVerticies(IMolecule mol) {
    for (IAtom atom : mol.atoms()) {
        int idx = mol.getAtomNumber(atom);
        if (!this.verticiesOfatoms.keySet().contains(idx)) {
            Vertex v = new Vertex();
            v.id = "?";
            v.vertices.add(idx);
            this.addVertex(v);
            this.verticiesOfatoms.put(idx, v);
        }
    }
}
Also used : IAtom(org.openscience.cdk.interfaces.IAtom)

Example 35 with IAtom

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

the class ContractedGraph method createLinks.

// Create links between contracted and unknown nodes
private void createLinks(IMolecule mol) {
    this.removeAllEdges(this.edgeSet());
    for (Object o : this.vertexSet()) {
        Vertex v = (Vertex) o;
        for (int idx : v.vertices) {
            IAtom a = mol.getAtom(idx);
            List<IAtom> neighbors = mol.getConnectedAtomsList(a);
            for (IAtom n : neighbors) {
                int aIdx = mol.getAtomNumber(n);
                if (!v.vertices.contains(aIdx)) {
                    // Base edge
                    Vertex vOa = this.verticiesOfatoms.get(aIdx);
                    String l0 = "";
                    String l1 = "";
                    // Labels
                    if (v.kind.containsKey(idx))
                        l0 = v.kind.get(idx).getName();
                    if (vOa.kind.containsKey(aIdx))
                        l1 = vOa.kind.get(aIdx).getName();
                    LabeledEdge edge = new LabeledEdge(v, vOa, l0, l1);
                    this.addEdge(edge);
                }
            }
        }
    }
}
Also used : IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

IAtom (org.openscience.cdk.interfaces.IAtom)46 IMolecule (org.openscience.cdk.interfaces.IMolecule)16 IBond (org.openscience.cdk.interfaces.IBond)13 ArrayList (java.util.ArrayList)10 Residue (model.Residue)8 Rule (model.Rule)6 Bond (org.openscience.cdk.Bond)6 Molecule (org.openscience.cdk.Molecule)6 MappedChain (algorithms.isomorphism.chains.MappedChain)5 HashMap (java.util.HashMap)5 CDKException (org.openscience.cdk.exception.CDKException)5 Match (algorithms.utils.Match)4 Test (org.junit.Test)4 Chain (algorithms.isomorphism.chains.Chain)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Vector (java.util.Vector)3 Family (model.Family)3 JSONObject (org.json.simple.JSONObject)3 Before (org.junit.Before)3