Search in sources :

Example 1 with ChemicalObject

use of model.ChemicalObject in project Smiles2Monomers by yoann-dufresne.

the class Isomorphism method searchFromPreviousMapping.

/**
 * Search a list of mapped blocs from a smaller mapped bloc
 * @param mb Initial mapped bloc
 * @param ext Extension to the previous mapped bloc
 * @return New mapped blocs.
 */
public static List<MappedChain> searchFromPreviousMapping(MappedChain mb, Extension ext, MatchingType type) {
    List<MappedChain> mbs = new ArrayList<>();
    ChemicalObject co = mb.getChemObject();
    IMolecule mol = co.getMolecule();
    List<Integer> neighbors = mb.getNeighborsBonds(mol);
    // Create a new bloc for each neighbor
    for (int idx : neighbors) {
        // Create bloc
        IBond nb = mol.getBond(idx);
        List<BondMapping> matchings = ext.match(nb, type);
        for (BondMapping bm : matchings) {
            int atomIdx0 = mol.getAtomNumber(bm.a0);
            int atomIdx1 = mol.getAtomNumber(bm.a1);
            int blocPosition0 = mb.getMappingIdx(atomIdx0);
            int blocPosition1 = mb.getMappingIdx(atomIdx1);
            int hydrogen0 = bm.h0;
            int hydrogen1 = bm.h1;
            Chain bloc = new Chain(mb.getChain(), ext, blocPosition0, blocPosition1);
            List<Integer> atoms = new ArrayList<>(mb.getAtomsMapping());
            if (blocPosition0 == -1)
                atoms.add(atomIdx0);
            if (blocPosition1 == -1)
                atoms.add(atomIdx1);
            List<Integer> bonds = new ArrayList<>(mb.getBondsMapping());
            bonds.add(mol.getBondNumber(nb));
            List<MatchingType> matchingTypes = new ArrayList<>(mb.getMatchings());
            matchingTypes.add(bm.matchingType);
            Map<Integer, Integer> hydrogens = new HashMap<>(mb.getHydrogensMapping());
            if (!hydrogens.containsKey(atomIdx0) || hydrogens.get(atomIdx0) <= hydrogen0)
                hydrogens.put(atomIdx0, hydrogen0);
            if (!hydrogens.containsKey(atomIdx1) || hydrogens.get(atomIdx1) <= hydrogen1)
                hydrogens.put(atomIdx1, hydrogen1);
            MappedChain newMb = new MappedChain(co, bloc, atoms, bonds, matchingTypes, hydrogens);
            if (!mbs.contains(newMb))
                mbs.add(newMb);
        }
    }
    return mbs;
}
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) ChemicalObject(model.ChemicalObject) BondMapping(algorithms.isomorphism.chains.Extension.BondMapping)

Example 2 with ChemicalObject

use of model.ChemicalObject in project Smiles2Monomers by yoann-dufresne.

the class ChainLearning method createBlocsFromPrevious.

private List<MappedChain> createBlocsFromPrevious(List<MappedChain> prevMbs) {
    List<MappedChain> nextMbs = new ArrayList<>();
    for (MappedChain mb : prevMbs) {
        ChemicalObject co = mb.getChemObject();
        IMolecule mol = co.getMolecule();
        List<Integer> neighbors = mb.getNeighborsBonds(mol);
        // Create a new bloc for each neighbor
        for (int idx : neighbors) {
            // Create bloc
            IBond nb = mol.getBond(idx);
            Extension ext = new Extension(nb);
            // Extension.setAromacityTest(false);
            List<MappedChain> newMbs = Isomorphism.searchFromPreviousMapping(mb, ext, MatchingType.EXACT);
            // Extension.setAromacityTest(true);
            nextMbs.addAll(newMbs);
        }
    }
    return nextMbs;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) ChemicalObject(model.ChemicalObject)

Example 3 with ChemicalObject

use of model.ChemicalObject in project Smiles2Monomers by yoann-dufresne.

the class CoveragesJsonLoader method objectFromJson.

@Override
protected Coverage objectFromJson(JSONObject obj) {
    // TODO : Create new parser with the files created by the new output functions
    System.err.println("From classe '" + CoveragesJsonLoader.class.getName() + "' method 'objectFromJson':");
    System.err.println("This is deprecated ! You will have some problems with recent json files !");
    ChemicalObject co = null;
    try {
        co = this.db.getObject("" + ((Number) obj.get("peptide")).intValue());
    } catch (NullPointerException e) {
        System.err.println(e.getMessage());
        System.err.println("Maybe coverage json and molecule json don't match");
        System.exit(2);
    }
    Coverage cov = new Coverage(co);
    JSONArray array = (JSONArray) obj.get("matches");
    for (Object o : array) {
        JSONObject jso = (JSONObject) o;
        Residue res = null;
        try {
            res = this.residues.getObject("" + ((Number) jso.get("residue")).intValue());
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
        JSONObject jMatch = (JSONObject) jso.get("match");
        Match match = new Match(res);
        JSONArray atoms = (JSONArray) jMatch.get("atoms");
        for (Object atObj : atoms) {
            JSONObject atom = (JSONObject) atObj;
            int idx = ((Number) atom.get("a")).intValue();
            match.addAtom(idx);
            match.addHydrogens(idx, ((Number) atom.get("h")).intValue());
        }
        JSONArray bonds = (JSONArray) jMatch.get("bonds");
        for (Object boObj : bonds) {
            int bond = ((Number) boObj).intValue();
            match.addBond(bond);
        }
        cov.addMatch(match);
    }
    cov.calculateGreedyCoverage();
    return cov;
}
Also used : JSONObject(org.json.simple.JSONObject) Residue(model.Residue) JSONArray(org.json.simple.JSONArray) ChemicalObject(model.ChemicalObject) Coverage(algorithms.utils.Coverage) JSONObject(org.json.simple.JSONObject) ChemicalObject(model.ChemicalObject) Match(algorithms.utils.Match)

Aggregations

ChemicalObject (model.ChemicalObject)3 ArrayList (java.util.ArrayList)2 IBond (org.openscience.cdk.interfaces.IBond)2 IMolecule (org.openscience.cdk.interfaces.IMolecule)2 Chain (algorithms.isomorphism.chains.Chain)1 BondMapping (algorithms.isomorphism.chains.Extension.BondMapping)1 MappedChain (algorithms.isomorphism.chains.MappedChain)1 Coverage (algorithms.utils.Coverage)1 Match (algorithms.utils.Match)1 HashMap (java.util.HashMap)1 Residue (model.Residue)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1