Search in sources :

Example 36 with IAtom

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

the class Extension method getSerial.

public String getSerial() {
    IAtom a0 = this.bond.getAtom(0);
    IAtom a1 = this.bond.getAtom(1);
    String name0 = a0.getFlag(CDKConstants.ISAROMATIC) ? a0.getSymbol().toLowerCase() : a0.getSymbol();
    String name1 = a1.getFlag(CDKConstants.ISAROMATIC) ? a1.getSymbol().toLowerCase() : a1.getSymbol();
    return name0 + "," + this.bond.getOrder().ordinal() + "," + name1 + "," + a0.getImplicitHydrogenCount() + "," + a1.getImplicitHydrogenCount();
}
Also used : IAtom(org.openscience.cdk.interfaces.IAtom)

Example 37 with IAtom

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

the class Extension method clone.

public Extension clone() {
    Extension ext = new Extension();
    IAtom a0 = null, a1 = null;
    try {
        a0 = (IAtom) this.bond.getAtom(0).clone();
        a1 = (IAtom) this.bond.getAtom(1).clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    ext.bond = new Bond(a0, a1, this.bond.getOrder());
    return ext;
}
Also used : Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 38 with IAtom

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

the class Extension method match.

/**
 * Match "this" extension on the bond from the chemical object with or without strict rules
 * @param bond Bond to match
 * @param light False for strict matching, true for aromatic, bond degree and hydrogen approximation.
 * @return list of matches
 */
public List<BondMapping> match(IBond bond, MatchingType type) {
    List<BondMapping> mappings = new ArrayList<>();
    IAtom a0 = bond.getAtom(0);
    IAtom a1 = bond.getAtom(1);
    IAtom e0 = this.bond.getAtom(0);
    IAtom e1 = this.bond.getAtom(1);
    int h0 = a0.getImplicitHydrogenCount();
    int h1 = a1.getImplicitHydrogenCount();
    int eh0 = e0.getImplicitHydrogenCount();
    int eh1 = e1.getImplicitHydrogenCount();
    // Mapping in bond direction
    if (this.areSameAtoms(e0, e1, a0, a1))
        if (this.lightToStrongMatching(e0, e1, eh0, eh1, a0, a1, h0, h1, this.bond, bond)) {
            if (this.strongToExactMatching(eh0, eh1, h0, h1))
                mappings.add(new BondMapping(bond, this, a0, a1, eh0, eh1, MatchingType.EXACT));
            else if (type != MatchingType.EXACT)
                mappings.add(new BondMapping(bond, this, a0, a1, eh0, eh1, MatchingType.STRONG));
        } else if (type == MatchingType.LIGHT) {
            mappings.add(new BondMapping(bond, this, a0, a1, 0, 0, MatchingType.LIGHT));
        }
    // Reverse mapping
    if (this.areSameAtoms(e0, e1, a1, a0))
        if (this.lightToStrongMatching(e0, e1, eh0, eh1, a1, a0, h1, h0, this.bond, bond)) {
            if (this.strongToExactMatching(eh0, eh1, h1, h0))
                mappings.add(new BondMapping(bond, this, a1, a0, eh0, eh1, MatchingType.EXACT));
            else if (type != MatchingType.EXACT)
                mappings.add(new BondMapping(bond, this, a1, a0, eh0, eh1, MatchingType.STRONG));
        } else if (type == MatchingType.LIGHT) {
            mappings.add(new BondMapping(bond, this, a1, a0, 0, 0, MatchingType.LIGHT));
        }
    return mappings;
}
Also used : ArrayList(java.util.ArrayList) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 39 with IAtom

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

the class HydrogenAdd method getFreeHydrogens.

/**
 * Transform mc parameter to correct parameters for arity calculation
 * @param mc
 * @return
 */
private int getFreeHydrogens(MappedChain mc) {
    int atomIdx = mc.getAtomsMapping().get(this.idx);
    IMolecule mol = mc.getChemObject().getMolecule();
    IAtom a = mol.getAtom(atomIdx);
    int mappedHydrogens = mc.getHydrogensMapping().get(atomIdx);
    int presentHydrogens = a.getImplicitHydrogenCount();
    return presentHydrogens - mappedHydrogens;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 40 with IAtom

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

the class MappedChain method addAllHydrogens.

/**
 * To add real hydrogens from the chemical object to the bloc mapping
 * @return new BlocMapping with hydrogens.
 */
public void addAllHydrogens() {
    // Create the list of extensions
    Chain b = this.bloc;
    while (b != null) {
        b.setSerial(null);
        Extension ext = b.getExt().clone();
        b.setExtension(ext);
        IAtom a0 = ext.getBond().getAtom(0);
        IAtom a1 = ext.getBond().getAtom(1);
        int hs = 0;
        int idx0 = this.atomsMapping.get(b.getAbsolutePosition1());
        hs = this.getChemObject().getMolecule().getAtom(idx0).getImplicitHydrogenCount();
        a0.setImplicitHydrogenCount(hs);
        this.hydrogensMapping.put(idx0, hs);
        int idx1 = this.atomsMapping.get(b.getAbsolutePosition2());
        hs = this.getChemObject().getMolecule().getAtom(idx1).getImplicitHydrogenCount();
        a1.setImplicitHydrogenCount(hs);
        this.hydrogensMapping.put(idx1, hs);
        if (a0.getAtomicNumber() == a1.getAtomicNumber() && a0.getFlag(CDKConstants.ISAROMATIC) == a1.getFlag(CDKConstants.ISAROMATIC) && a0.getImplicitHydrogenCount() == a1.getImplicitHydrogenCount() && b.getPosition1() > b.getPosition2()) {
            b.invertPositions();
        }
        b = b.getSubBlc();
    }
}
Also used : 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