Search in sources :

Example 6 with Rule

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

the class ResidueJsonLoader method fillLinksJSO.

@SuppressWarnings("unchecked")
private String fillLinksJSO(JSONArray links, Residue res) {
    IMolecule mol = res.getMolecule();
    AtomContainerManipulator.convertImplicitToExplicitHydrogens(mol);
    String smiles = SmilesConverter.conv.mol2Smiles(mol, false);
    List<IAtom> order = SmilesConverter.conv.getOrder();
    for (IAtom a : res.getAtomicLinks().keySet()) {
        JSONObject jso = new JSONObject();
        Rule rule = res.getAtomicLinks().get(a);
        jso.put("name", rule.getName());
        jso.put("atom", order.indexOf(a));
        links.add(jso);
    }
    AtomContainerManipulator.removeHydrogens(mol);
    return smiles;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) JSONObject(org.json.simple.JSONObject) Rule(model.Rule) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 7 with Rule

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

the class ChainsFamilyMatching method addToCoverage.

private void addToCoverage(Family family, MappedChain mc, Residue res) {
    Match match = new Match(res);
    match.addAtoms(mc.getAtomsMapping());
    match.addBonds(mc.getBondsMapping());
    match.addHydrogens(mc.getHydrogensMapping());
    for (int idx = 0; idx < mc.getMatchings().size(); idx++) {
        match.addQuality(mc.getBondsMapping().get(idx), mc.getMatchings().get(idx));
    }
    // Compute external bonds by aligning chain on residue
    // 1- Retrieve the chain on root residue
    int current = 200;
    List<MappedChain> onResidue = null;
    Residue rootMol = null;
    for (Residue root : family.getRoots()) {
        List<MappedChain> mcs = Isomorphism.searchAChain(mc.getChain(), root, MatchingType.EXACT);
        if (mcs.size() > 0 && current > mcs.size()) {
            current = mcs.size();
            onResidue = mcs;
            rootMol = root;
        }
    }
    // 2- Look for atoms of interest
    MappedChain resMapping = onResidue.get(0);
    for (IAtom ia : rootMol.getAtomicLinks().keySet()) {
        Rule r = rootMol.getAtomicLinks().get(ia);
        int resMolIdx = rootMol.getMolecule().getAtomNumber(ia);
        int chainIdx = resMapping.getAtomsMapping().indexOf(resMolIdx);
        match.addExtLink(mc.getAtomsMapping().get(chainIdx), r);
    }
    // Add the match
    if (!this.coverage.getMatches().contains(match))
        this.coverage.addMatch(match);
}
Also used : MappedChain(algorithms.isomorphism.chains.MappedChain) Residue(model.Residue) Rule(model.Rule) IAtom(org.openscience.cdk.interfaces.IAtom) Match(algorithms.utils.Match)

Example 8 with Rule

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

the class ResidueCreator method createResidues.

/**
 * Create all residues from the argument monomers database according to rules entered in paramaters of the constructor.
 * @param monosDBName A monomers database.
 * @return All possible residues found.
 */
public FamilyDB createResidues(MonomersDB monosDB) {
    FamilyDB famDB = new FamilyDB();
    famDB.init(monosDB);
    for (Family family : famDB.getFamilies()) {
        this.residuesFromMonomers(family);
        for (Residue res : family.getResidues()) {
            IMolecule oldMol = res.getMolecule();
            res.setMol(new Molecule(AtomContainerManipulator.removeHydrogens(res.getMolecule())));
            IMolecule newMol = res.getMolecule();
            Map<IAtom, IAtom> conversion = new HashMap<>();
            int idx = 0;
            for (IAtom a : oldMol.atoms()) {
                if (!"H".equals(a.getSymbol())) {
                    conversion.put(a, newMol.getAtom(idx));
                    idx++;
                }
            }
            Map<IAtom, Rule> oldLinks = new HashMap<>(res.getAtomicLinks());
            res.getAtomicLinks().clear();
            for (IAtom oldA : oldLinks.keySet()) {
                Rule rule = oldLinks.get(oldA);
                res.addLink(conversion.get(oldA), rule);
            }
        }
    }
    return famDB;
}
Also used : Molecule(org.openscience.cdk.Molecule) IMolecule(org.openscience.cdk.interfaces.IMolecule) IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) HashMap(java.util.HashMap) Family(model.Family) FamilyDB(db.FamilyDB) Rule(model.Rule) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

Rule (model.Rule)8 Residue (model.Residue)6 IAtom (org.openscience.cdk.interfaces.IAtom)6 Family (model.Family)3 IMolecule (org.openscience.cdk.interfaces.IMolecule)3 FamilyDB (db.FamilyDB)2 Monomer (model.Monomer)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 Test (org.junit.Test)2 MappedChain (algorithms.isomorphism.chains.MappedChain)1 Match (algorithms.utils.Match)1 RulesDB (db.RulesDB)1 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Molecule (org.openscience.cdk.Molecule)1