use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class BondAdd method searchAtoms.
public void searchAtoms(MappedChain mc, MatchingType type) throws AtomNotFound {
this.mol = mc.getChemObject().getMolecule();
// Init real atom idxs.
int atomIdx = -1;
int neiIdx = -1;
this.expected = null;
if (this.idx1 == -1) {
atomIdx = mc.getAtomsMapping().get(this.idx2);
neiIdx = this.idx1;
expected = this.ext.getBond().getAtom(0);
} else {
atomIdx = mc.getAtomsMapping().get(this.idx1);
neiIdx = this.idx2;
this.expected = this.ext.getBond().getAtom(1);
}
// Search in neighborhood.
IAtom atom = this.mol.getAtom(atomIdx);
List<IAtom> neighbors = this.mol.getConnectedAtomsList(atom);
this.neiAtom = null;
// Adding with two atoms already in the previous mapped chain
if (neiIdx != -1) {
this.neiAtom = this.mol.getAtom(mc.getAtomsMapping().get(neiIdx));
if (!neighbors.contains(this.neiAtom)) {
throw new AtomNotFound();
}
} else // Adding with only one atom in the previous matching
{
for (IAtom a : neighbors) {
if (mc.getAtomsMapping().contains(this.mol.getAtomNumber(a)))
continue;
IBond bond = this.mol.getBond(atom, a);
if (this.expected.getSymbol().equals(a.getSymbol())) {
if (bond.getOrder() == this.ext.getBond().getOrder() && this.expected.getFlag(CDKConstants.ISAROMATIC) == a.getFlag(CDKConstants.ISAROMATIC) && this.expected.getImplicitHydrogenCount().intValue() <= a.getImplicitHydrogenCount().intValue()) {
this.neiAtom = a;
this.neiHydro = this.expected.getImplicitHydrogenCount().intValue();
if (this.expected.getImplicitHydrogenCount().intValue() == a.getImplicitHydrogenCount().intValue()) {
this.matchingType = MatchingType.EXACT;
break;
} else if (type != MatchingType.EXACT) {
this.matchingType = MatchingType.STRONG;
break;
}
} else if (type == MatchingType.LIGHT) {
this.neiAtom = a;
this.neiHydro = 0;
this.matchingType = MatchingType.LIGHT;
break;
}
}
}
if (this.neiAtom == null) {
throw new AtomNotFound();
}
}
this.bond = this.mol.getBond(atom, neiAtom);
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class ChainLearning method recurChildrenAdds.
private void recurChildrenAdds(FamilyChainsDB fc, Residue from, Set<Residue> children) {
for (Residue child : children) {
List<ChainAdd> adds = fc.getAdds(child);
// If extensions already exist, jump to the next son.
if (adds.size() > 0)
continue;
List<MappedChain> mcs = this.calculateMapping(fc, child, from, new MappedChain(child));
// Collections.sort(mcs, new MappedChainComparator());
MappedChain mc = mcs.get(0);
// Hydrogen adds
for (int atomIdx : mc.getAtomsMapping()) {
IAtom a = mc.getChemObject().getMolecule().getAtom(atomIdx);
int chainIdx = mc.getAtomsMapping().indexOf(atomIdx);
Map<Integer, Integer> mapping = mc.getHydrogensMapping();
int mappingHydrogens = mapping.containsKey(atomIdx) ? mapping.get(atomIdx) : 0;
int molHydrogens = a.getImplicitHydrogenCount();
if (mappingHydrogens < molHydrogens)
adds.add(new HydrogenAdd(from, chainIdx, molHydrogens - mappingHydrogens));
}
// Extensions
IMolecule resMol = mc.getChemObject().getMolecule();
for (IBond bond : resMol.bonds()) {
int bondIdx = resMol.getBondNumber(bond);
if (mc.getBondsMapping().contains(bondIdx))
continue;
Extension ext = new Extension(bond);
List<MappedChain> tmpMappings = Isomorphism.searchFromPreviousMapping(mc, ext, MatchingType.EXACT);
for (MappedChain tmp : tmpMappings) if (tmp.getBondsMapping().get(tmp.getBondsMapping().size() - 1) == bondIdx) {
Chain chain = tmp.getChain();
BondAdd ba = new BondAdd(from, ext, chain.getPosition1(), chain.getPosition2());
adds.add(ba);
}
}
/**/
this.recurChildrenAdds(fc, child, fc.getFamily().getChildrenOf(child));
}
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class Modulation method indexCoverage.
/**
* Read a coverage and extract for each position all the possible matchings
* @param cov
* @return
*/
private void indexCoverage(Coverage cov) {
this.index = new HashMap<>();
this.usedIndex = new HashMap<>();
IMolecule mol = cov.getChemicalObject().getMolecule();
for (IAtom a : mol.atoms()) {
this.index.put(mol.getAtomNumber(a), new HashSet<Match>());
this.usedIndex.put(mol.getAtomNumber(a), new HashSet<Match>());
}
// Global index
for (Match match : cov.getMatches()) for (int i : match.getAtoms()) this.index.get(i).add(match);
// Used index
for (Match match : cov.getUsedMatches()) for (int i : match.getAtoms()) this.usedIndex.get(i).add(match);
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class Coverage method getCorrectness.
public double getCorrectness(FamilyDB families) {
if (!this.alreadyCalculate)
this.calculateGreedyCoverage();
if (this.corrects == null)
this.calculateCorrectIncorrectNotFound(families);
int pepAtoms = 0;
for (@SuppressWarnings("unused") IAtom a : this.co.getMolecule().atoms()) pepAtoms++;
int corAtoms = 0;
for (Residue res : this.corrects.keySet()) {
int resAtoms = res.getMolecule().getAtomCount();
corAtoms += resAtoms * this.corrects.get(res);
}
double ratio = new Double(corAtoms) / new Double(pepAtoms);
return ratio;
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class Extension method equals.
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Extension))
return false;
Extension ext = (Extension) obj;
if (!ext.bond.getOrder().equals(this.bond.getOrder()))
return false;
IAtom oa0 = ext.bond.getAtom(0);
int oh0 = oa0.getImplicitHydrogenCount();
IAtom oa1 = ext.bond.getAtom(1);
int oh1 = oa1.getImplicitHydrogenCount();
IAtom ta0 = this.bond.getAtom(0);
int th0 = ta0.getImplicitHydrogenCount();
IAtom ta1 = this.bond.getAtom(1);
int th1 = ta1.getImplicitHydrogenCount();
if (oa0.getSymbol().equals(ta0.getSymbol()) && oa1.getSymbol().equals(ta1.getSymbol()) && th0 == oh0 && th1 == oh1)
return true;
if (oa0.getSymbol().equals(ta1.getSymbol()) && oa1.getSymbol().equals(ta0.getSymbol()) && th0 == oh1 && th1 == oh0)
return true;
return false;
}
Aggregations