Search in sources :

Example 11 with IAtom

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

the class IsomorphismTests method setUp.

@Before
public void setUp() throws Exception {
    // Database
    Monomer[] monos = new Monomer[1];
    Polymer pepTest = new Polymer(0, "malformin A1", "O=C1NC2C(=O)NC(C(=O)NC(C(=O)NC(C(=O)NC1CSSC2)C(C)CC)CC(C)C)C(C)C", monos);
    // Extensions
    IAtom a = new Atom("C");
    IBond b1 = new Bond(new Atom("S"), a, Order.SINGLE);
    this.ext1 = new Extension(b1);
    a = new Atom("C");
    IAtom a2 = new Atom("C");
    IBond b2 = new Bond(a, a2, Order.SINGLE);
    this.ext2 = new Extension(b2);
    // Mapped blocs
    this.mb0 = new MappedChain(pepTest, null, new ArrayList<Integer>(), new ArrayList<Integer>(), new ArrayList<MatchingType>(), new HashMap<Integer, Integer>());
    // For blocs Tests
    this.bloc = new Chain("S,0,c,0,0,-1,-1;c,0,c,0,0,-1,1");
}
Also used : Extension(algorithms.isomorphism.chains.Extension) MappedChain(algorithms.isomorphism.chains.MappedChain) Chain(algorithms.isomorphism.chains.Chain) MappedChain(algorithms.isomorphism.chains.MappedChain) HashMap(java.util.HashMap) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) Polymer(model.Polymer) Monomer(model.Monomer) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.silent.Atom) IAtom(org.openscience.cdk.interfaces.IAtom) Before(org.junit.Before)

Example 12 with IAtom

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

the class CoveragesJsonLoader method getJSONMatches.

@SuppressWarnings("unchecked")
private JSONObject getJSONMatches(Coverage cov) {
    JSONObject graph = new JSONObject();
    JSONArray atoms = new JSONArray();
    graph.put("atoms", atoms);
    JSONArray bonds = new JSONArray();
    graph.put("bonds", bonds);
    Set<IBond> usedBonds = new HashSet<IBond>();
    int matchId = 0;
    for (Match match : cov.getUsedMatches()) {
        // Atoms
        for (int a : match.getAtoms()) {
            JSONObject atom = new JSONObject();
            // CDK informations
            atom.put("cdk_idx", a);
            // Atom informations
            IAtom ia = cov.getChemicalObject().getMolecule().getAtom(a);
            atom.put("name", ia.getSymbol());
            atom.put("hydrogens", match.getHydrogensFrom(a));
            // Residue informations
            atom.put("res", match.getResidue().getId());
            atom.put("matchIdx", matchId);
            atoms.add(atom);
        }
        // Bonds
        for (int b : match.getBonds()) {
            IBond ib = cov.getChemicalObject().getMolecule().getBond(b);
            usedBonds.add(ib);
            JSONObject bond = new JSONObject();
            // CDK informations
            bond.put("cdk_idx", b);
            // atoms linked
            JSONArray linkedAtoms = new JSONArray();
            for (IAtom a : ib.atoms()) {
                linkedAtoms.add(cov.getChemicalObject().getMolecule().getAtomNumber(a));
            }
            bond.put("arity", ib.getOrder().numeric());
            bond.put("atoms", linkedAtoms);
            bond.put("res", match.getResidue().getId());
            bonds.add(bond);
        }
        matchId++;
    }
    IMolecule mol = cov.getChemicalObject().getMolecule();
    for (IBond ib : mol.bonds()) {
        if (!usedBonds.contains(ib)) {
            JSONObject bond = new JSONObject();
            // CDK informations
            bond.put("cdk_idx", mol.getBondNumber(ib));
            // atoms linked
            JSONArray linkedAtoms = new JSONArray();
            for (IAtom a : ib.atoms()) {
                linkedAtoms.add(mol.getAtomNumber(a));
            }
            bond.put("arity", ib.getOrder().numeric());
            bond.put("atoms", linkedAtoms);
            bonds.add(bond);
        }
    }
    return graph;
}
Also used : JSONObject(org.json.simple.JSONObject) IMolecule(org.openscience.cdk.interfaces.IMolecule) JSONArray(org.json.simple.JSONArray) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) HashSet(java.util.HashSet) Match(algorithms.utils.Match)

Example 13 with IAtom

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

the class Residue method explicitToImplicitHydrogens.

public void explicitToImplicitHydrogens() {
    IMolecule mol = this.getMolecule();
    for (IAtom a : mol.atoms()) a.setImplicitHydrogenCount(0);
    List<IAtom> toRemove = new ArrayList<>();
    for (IAtom a : mol.atoms()) if (a.getAtomTypeName().equals("H")) {
        IAtom connected = mol.getConnectedAtomsList(a).get(0);
        connected.setImplicitHydrogenCount(connected.getImplicitHydrogenCount() + 1);
        toRemove.add(a);
    }
    for (IAtom a : toRemove) {
        mol.removeBond(mol.getConnectedBondsList(a).get(0));
        mol.removeAtom(a);
    }
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) ArrayList(java.util.ArrayList) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 14 with IAtom

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

the class Residue method getIdxLinks.

public Map<Integer, Rule> getIdxLinks() {
    if (this.idxLinkedAtoms == null) {
        this.idxLinkedAtoms = new HashMap<>();
        for (IAtom a : this.linkedAtoms.keySet()) {
            int idx = this.getMolecule().getAtomNumber(a);
            this.idxLinkedAtoms.put(idx, this.linkedAtoms.get(a));
        }
    }
    return this.idxLinkedAtoms;
}
Also used : IAtom(org.openscience.cdk.interfaces.IAtom)

Example 15 with IAtom

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

the class Isomorphism method searchFromPreviousMapping.

/**/
public static List<MappedChain> searchFromPreviousMapping(MappedChain mc, Extension ext, int idx1, int idx2, MatchingType type) {
    IMolecule mol = mc.getChemObject().getMolecule();
    int extIdx = idx1 == -1 ? idx2 : idx1;
    List<MappedChain> mappings = new ArrayList<>();
    // Connected bonds search
    List<IBond> connectedBonds = null;
    if (extIdx == -1) {
        connectedBonds = new ArrayList<>();
        for (IBond bond : mol.bonds()) connectedBonds.add(bond);
    } else {
        IAtom extAtom = mol.getAtom(mc.getAtomsMapping().get(extIdx));
        connectedBonds = mol.getConnectedBondsList(extAtom);
    }
    for (IBond neighbor : connectedBonds) {
        // No need to search bonds already present in mapping.
        if (mc.getBondsMapping().contains(mol.getBondNumber(neighbor)))
            continue;
        List<BondMapping> bms = ext.match(neighbor, type);
        for (BondMapping bm : bms) {
            // Verification of the compatibility with previous matching
            if (idx1 != -1 && mol.getAtomNumber(bm.a0) != mc.getAtomsMapping().get(idx1))
                continue;
            if (idx2 != -1 && mol.getAtomNumber(bm.a1) != mc.getAtomsMapping().get(idx2))
                continue;
            // Creation of the new mapping
            Chain chain = new Chain(mc.getChain(), ext, idx1, idx2);
            List<Integer> atoms = new ArrayList<>(mc.getAtomsMapping());
            Map<Integer, Integer> hydrogens = new HashMap<>(mc.getHydrogensMapping());
            if (idx1 == -1) {
                int an = mol.getAtomNumber(bm.a0);
                // To avoid cycles where there is no cycle.
                if (mc.getAtomsMapping().contains(an))
                    continue;
                atoms.add(an);
                hydrogens.put(an, bm.h0);
            }
            if (idx2 == -1) {
                int an = mol.getAtomNumber(bm.a1);
                // To avoid cycles where there is no cycle.
                if (mc.getAtomsMapping().contains(an))
                    continue;
                atoms.add(an);
                hydrogens.put(an, bm.h1);
            }
            List<Integer> bonds = new ArrayList<>(mc.getBondsMapping());
            bonds.add(mol.getBondNumber(neighbor));
            List<MatchingType> matchings = new ArrayList<>(mc.getMatchings());
            matchings.add(bm.matchingType);
            MappedChain newMc = new MappedChain(mc.getChemObject(), chain, atoms, bonds, matchings, hydrogens);
            mappings.add(newMc);
        }
    }
    return mappings;
}
Also used : MappedChain(algorithms.isomorphism.chains.MappedChain) Chain(algorithms.isomorphism.chains.Chain) MappedChain(algorithms.isomorphism.chains.MappedChain) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) IMolecule(org.openscience.cdk.interfaces.IMolecule) BondMapping(algorithms.isomorphism.chains.Extension.BondMapping) 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