Search in sources :

Example 11 with Match

use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.

the class ChainsFamilyMatching method addToCoverage.

private void addToCoverage(Family family, MappedChain mc, Residue res) {
    Match match = new Match(res);
    match.addAtoms(mc.getAtomsMapping());
    match.addBonds(mc.getBondsMapping());
    match.addHydrogens(mc.getHydrogensMapping());
    for (int idx = 0; idx < mc.getMatchings().size(); idx++) {
        match.addQuality(mc.getBondsMapping().get(idx), mc.getMatchings().get(idx));
    }
    // Compute external bonds by aligning chain on residue
    // 1- Retrieve the chain on root residue
    int current = 200;
    List<MappedChain> onResidue = null;
    Residue rootMol = null;
    for (Residue root : family.getRoots()) {
        List<MappedChain> mcs = Isomorphism.searchAChain(mc.getChain(), root, MatchingType.EXACT);
        if (mcs.size() > 0 && current > mcs.size()) {
            current = mcs.size();
            onResidue = mcs;
            rootMol = root;
        }
    }
    // 2- Look for atoms of interest
    MappedChain resMapping = onResidue.get(0);
    for (IAtom ia : rootMol.getAtomicLinks().keySet()) {
        Rule r = rootMol.getAtomicLinks().get(ia);
        int resMolIdx = rootMol.getMolecule().getAtomNumber(ia);
        int chainIdx = resMapping.getAtomsMapping().indexOf(resMolIdx);
        match.addExtLink(mc.getAtomsMapping().get(chainIdx), r);
    }
    // Add the match
    if (!this.coverage.getMatches().contains(match))
        this.coverage.addMatch(match);
}
Also used : MappedChain(algorithms.isomorphism.chains.MappedChain) Residue(model.Residue) Rule(model.Rule) IAtom(org.openscience.cdk.interfaces.IAtom) Match(algorithms.utils.Match)

Example 12 with Match

use of algorithms.utils.Match 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 13 with Match

use of algorithms.utils.Match 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

Match (algorithms.utils.Match)13 HashSet (java.util.HashSet)4 Residue (model.Residue)4 IAtom (org.openscience.cdk.interfaces.IAtom)4 IMolecule (org.openscience.cdk.interfaces.IMolecule)4 Coverage (algorithms.utils.Coverage)3 ArrayList (java.util.ArrayList)3 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 IBond (org.openscience.cdk.interfaces.IBond)2 MappedChain (algorithms.isomorphism.chains.MappedChain)1 AtomColorer (io.imgs.coloration.ColoredAtomGenerator.AtomColorer)1 Color (java.awt.Color)1 HashMap (java.util.HashMap)1 Stack (java.util.Stack)1 ChemicalObject (model.ChemicalObject)1 Family (model.Family)1 Link (model.Family.Link)1 Rule (model.Rule)1 CDKException (org.openscience.cdk.exception.CDKException)1