Search in sources :

Example 11 with Chain

use of algorithms.isomorphism.chains.Chain in project Smiles2Monomers by yoann-dufresne.

the class FamilyChainIO method objectFromJson.

@Override
protected FamilyChainsDB objectFromJson(JSONObject jso) {
    // FC creation
    String famName = (String) jso.get("family");
    if (famName.contains("€"))
        famName = famName.split("€")[0];
    Family fam = this.families.getObject(famName);
    FamilyChainsDB fc = new FamilyChainsDB(fam);
    // Roots
    JSONObject jsonRoots = (JSONObject) jso.get("roots");
    for (Object objIdx : jsonRoots.keySet()) {
        String idx = (String) objIdx;
        fc.addRootChain(this.residues.getObject(idx), new Chain((String) jsonRoots.get(objIdx)));
    }
    // Adds
    JSONObject jsonAdds = (JSONObject) jso.get("extensions");
    for (Object objIdx : jsonAdds.keySet()) {
        String idx = (String) objIdx;
        Residue current = this.residues.getObject(idx);
        JSONArray jsonAddsList = (JSONArray) jsonAdds.get(objIdx);
        for (Object obj : jsonAddsList) {
            JSONObject add = (JSONObject) obj;
            Residue from = this.residues.getObject((String) add.get("from"));
            ChainAdd ca = null;
            // TODO : Change it for better usage of genericity.
            switch((String) add.get("type")) {
                case "hydrogen":
                    ca = new HydrogenAdd(from, ((Number) add.get("idx")).intValue(), ((Number) add.get("num")).intValue());
                    break;
                case "extension":
                    ca = new BondAdd(from, new Extension((String) add.get("ext")), ((Number) add.get("idx1")).intValue(), ((Number) add.get("idx2")).intValue());
                    break;
                default:
                    break;
            }
            fc.addAnAdd(current, ca);
        }
    }
    return fc;
}
Also used : Chain(algorithms.isomorphism.chains.Chain) HydrogenAdd(algorithms.isomorphism.chains.HydrogenAdd) JSONArray(org.json.simple.JSONArray) Extension(algorithms.isomorphism.chains.Extension) FamilyChainsDB(algorithms.isomorphism.chains.FamilyChainsDB) JSONObject(org.json.simple.JSONObject) Residue(model.Residue) ChainAdd(algorithms.isomorphism.chains.ChainAdd) Family(model.Family) JSONObject(org.json.simple.JSONObject) BondAdd(algorithms.isomorphism.chains.BondAdd)

Aggregations

Chain (algorithms.isomorphism.chains.Chain)11 MappedChain (algorithms.isomorphism.chains.MappedChain)5 Test (org.junit.Test)4 ChainLearning (algorithms.isomorphism.chains.ChainLearning)3 ChainsIndex (algorithms.isomorphism.chains.ChainLearning.ChainsIndex)3 Extension (algorithms.isomorphism.chains.Extension)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 IAtom (org.openscience.cdk.interfaces.IAtom)3 IBond (org.openscience.cdk.interfaces.IBond)3 ChainAdd (algorithms.isomorphism.chains.ChainAdd)2 BondMapping (algorithms.isomorphism.chains.Extension.BondMapping)2 FamilyChainsDB (algorithms.isomorphism.chains.FamilyChainsDB)2 Residue (model.Residue)2 Bond (org.openscience.cdk.Bond)2 IMolecule (org.openscience.cdk.interfaces.IMolecule)2 Atom (org.openscience.cdk.silent.Atom)2 BondAdd (algorithms.isomorphism.chains.BondAdd)1 FrequencesIndex (algorithms.isomorphism.chains.ChainLearning.FrequencesIndex)1