Search in sources :

Example 26 with IMolecule

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

the class Chain method getPrevArity.

public int getPrevArity() {
    IAtom a = null;
    if (this.atoms == null)
        this.getMolecule();
    if (this.position1 == -1 && this.position2 == -1)
        return 1;
    else if (this.position1 != -1) {
        a = this.atoms.get(this.position1);
    } else {
        a = this.atoms.get(this.position2);
    }
    IMolecule mol = this.getMolecule();
    int valency = 1;
    try {
        valency = sc.calculateNumberOfImplicitHydrogens(a);
    } catch (CDKException e) {
        e.printStackTrace();
    }
    int hydrogens = a.getImplicitHydrogenCount();
    int connected = mol.getConnectedAtomsCount(a);
    int arity = valency - connected - hydrogens + 1;
    return arity < 1 ? 1 : arity;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) CDKException(org.openscience.cdk.exception.CDKException) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 27 with IMolecule

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

the class ResidueCreator method removeExclusions.

/*
	 * Remove results corresponding to an exclusion in rule
	 */
private void removeExclusions(List<List<RMap>> matches, String ex, IMolecule mol) {
    // Verifying exclusions
    boolean areExclusion = false;
    IMolecule exclusionMol = null;
    try {
        exclusionMol = SmilesConverter.conv.transform(ex, false, false, true);
    } catch (InvalidSmilesException e) {
        System.err.println("Impossible to parse " + ex);
        return;
    }
    try {
        areExclusion = UniversalIsomorphismTester.isSubgraph(mol, exclusionMol);
    } catch (CDKException e) {
        e.printStackTrace();
    }
    if (areExclusion) {
        List<RMap> toExclude = null;
        boolean flag = false;
        List<List<RMap>> exclusions = null;
        try {
            exclusions = UniversalIsomorphismTester.getSubgraphAtomsMaps(mol, exclusionMol);
        } catch (CDKException e) {
            e.printStackTrace();
        }
        for (List<RMap> exclusion : exclusions) {
            for (List<RMap> match : matches) {
                for (RMap rmMatch : match) {
                    for (RMap exId : exclusion) {
                        if (rmMatch.getId1() == exId.getId1()) {
                            flag = true;
                            break;
                        }
                    }
                    if (flag)
                        break;
                }
                if (flag) {
                    toExclude = match;
                    break;
                }
            }
            if (flag) {
                matches.remove(toExclude);
                toExclude = null;
                flag = false;
            }
        }
    }
/**/
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) CDKException(org.openscience.cdk.exception.CDKException) ArrayList(java.util.ArrayList) List(java.util.List) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) RMap(org.openscience.cdk.isomorphism.mcss.RMap)

Example 28 with IMolecule

use of org.openscience.cdk.interfaces.IMolecule 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

IMolecule (org.openscience.cdk.interfaces.IMolecule)28 IAtom (org.openscience.cdk.interfaces.IAtom)12 ArrayList (java.util.ArrayList)7 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)7 Residue (model.Residue)6 IBond (org.openscience.cdk.interfaces.IBond)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 CDKException (org.openscience.cdk.exception.CDKException)5 MappedChain (algorithms.isomorphism.chains.MappedChain)4 Match (algorithms.utils.Match)4 HashMap (java.util.HashMap)4 Rule (model.Rule)3 JSONObject (org.json.simple.JSONObject)3 Chain (algorithms.isomorphism.chains.Chain)2 BondMapping (algorithms.isomorphism.chains.Extension.BondMapping)2 MonomersDB (db.MonomersDB)2 PolymersDB (db.PolymersDB)2 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)2 IOException (java.io.IOException)2