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;
}
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;
}
}
}
/**/
}
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;
}
Aggregations