use of algorithms.utils.Coverage in project Smiles2Monomers by yoann-dufresne.
the class IsomorphismFamilyMatcher method matchFamilly.
@Override
public Coverage matchFamilly(Family family) {
// Initialization
Coverage cov = new Coverage(co);
IMolecule mol = co.getMolecule();
Set<Residue> markSet = new HashSet<>();
Stack<Residue> searchSet = new Stack<>();
searchSet.addAll(family.getRoots());
// For all the nodes in the search group.
while (!searchSet.isEmpty()) {
Residue currentRes = searchSet.pop();
// Search the current residue in mol.
try {
this.sqt.setSmarts(currentRes.getSmiles());
} catch (CDKException e) {
e.printStackTrace();
}
boolean isMatching = false;
try {
long time = System.currentTimeMillis();
isMatching = this.sqt.matches(mol);
if (verbose)
System.out.println(" Search for " + currentRes.getName() + " in " + (System.currentTimeMillis() - time));
} catch (CDKException e) {
e.printStackTrace();
}
// If there is at least one occurrence.
if (isMatching) {
// Add matches to the coverage
List<Match> matches = new ArrayList<>();
for (List<Integer> lMatch : sqt.getMatchingAtoms()) {
Match match = new Match(currentRes);
for (int i : lMatch) match.addAtom(i);
matches.add(match);
}
// Change to compare.
cov.addListMatches(currentRes, matches);
// Mark current residue to possibly add children.
markSet.add(currentRes);
// Add children with all parents marked
Set<Residue> children = family.getChildrenOf(currentRes);
for (Residue child : children) {
boolean canBeAdded = true;
for (Link dependance : family.getDepandances()) if (dependance.getTo().equals(child))
if (!markSet.contains(dependance.getFrom())) {
canBeAdded = false;
break;
}
if (canBeAdded)
searchSet.add(child);
}
}
}
return cov;
}
use of algorithms.utils.Coverage in project Smiles2Monomers by yoann-dufresne.
the class MonomericSpliting method matchAllFamilies.
/**
* Function to match independently all families onto the polymer.
* Can easily be parallelized
* @param matchType Strict/Light
*/
private void matchAllFamilies(MatchingType matchType) {
for (Family family : this.families.getFamilies()) {
/*/ Display
if (verbose) {
System.out.println("In " + polName);
System.out.println(" Family " + i++ + "/" + nbFamilies);
}/**/
// Time initialization
// long time = System.currentTimeMillis();
// Matching
this.matcher.setAllowLightMatch(matchType);
Coverage cov = this.matcher.matchFamilly(family);
if (matchType.equals(MatchingType.LIGHT)) {
for (Match match : cov.getMatches()) {
Match transformed = DeepenMatcher.transform(match, this.coverage.getCurrentMaskedMol(), this.coverage.getChemicalObject().getMolecule());
this.coverage.addMatch(transformed);
}
} else
this.coverage.addMatches(cov);
/*if (verbose)
System.out.println(" Search " + matchType.getClass().getCanonicalName() +
" for family " + family.getName() + " in " + (System.currentTimeMillis()-time) + "\n");/**/
}
}
Aggregations