Search in sources :

Example 11 with Coverage

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;
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) ArrayList(java.util.ArrayList) Coverage(algorithms.utils.Coverage) Stack(java.util.Stack) Match(algorithms.utils.Match) IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) Link(model.Family.Link) HashSet(java.util.HashSet)

Example 12 with Coverage

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");/**/
    }
}
Also used : Family(model.Family) Coverage(algorithms.utils.Coverage) Match(algorithms.utils.Match)

Aggregations

Coverage (algorithms.utils.Coverage)12 ColorsMap (io.imgs.PictureCoverageGenerator.ColorsMap)5 File (java.io.File)5 Residue (model.Residue)4 Match (algorithms.utils.Match)3 FamilyDB (db.FamilyDB)2 MonomersDB (db.MonomersDB)2 PolymersDB (db.PolymersDB)2 RulesDB (db.RulesDB)2 Coverages2HTML (io.html.Coverages2HTML)2 ImagesGeneration (io.imgs.ImagesGeneration)2 CoveragesJsonLoader (io.loaders.json.CoveragesJsonLoader)2 MonomersJsonLoader (io.loaders.json.MonomersJsonLoader)2 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)2 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)2 MonomersSerialization (io.loaders.serialization.MonomersSerialization)2 OutputZiper (io.zip.OutputZiper)2 HashMap (java.util.HashMap)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2