Search in sources :

Example 1 with Match

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

the class PictureCoverageGenerator method createPNG.

public ColorsMap createPNG(Coverage coverage, File outfile) {
    ColorsMap coverageColors = new ColorsMap();
    AtomColorer ac = this.cag.getColorer();
    IMolecule mol = coverage.getMolecule(false);
    List<Color> colors = ColorsGenerator.HsbColorsGeneration(coverage.nbMatchesForCoverage());
    int i = 0;
    for (Match match : coverage.getUsedMatches()) {
        Residue res = match.getResidue();
        List<Color> matchesColor = coverageColors.containsKey(res) ? coverageColors.get(res) : new ArrayList<Color>();
        for (int idx : match.getAtoms()) {
            if (!"H".equals(coverage.getMolecule(true).getAtom(idx).getSymbol()))
                ac.setColor(mol.getAtom(idx), colors.get(i));
        }
        matchesColor.add(colors.get(i));
        coverageColors.put(res, matchesColor);
        i++;
    }
    this.createPNG(mol, outfile);
    ac.resetColors();
    return coverageColors;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) Color(java.awt.Color) AtomColorer(io.imgs.coloration.ColoredAtomGenerator.AtomColorer) Match(algorithms.utils.Match)

Example 2 with Match

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

the class CoveragesJsonLoader method getJSONMatches.

@SuppressWarnings("unchecked")
private JSONObject getJSONMatches(Coverage cov) {
    JSONObject graph = new JSONObject();
    JSONArray atoms = new JSONArray();
    graph.put("atoms", atoms);
    JSONArray bonds = new JSONArray();
    graph.put("bonds", bonds);
    Set<IBond> usedBonds = new HashSet<IBond>();
    int matchId = 0;
    for (Match match : cov.getUsedMatches()) {
        // Atoms
        for (int a : match.getAtoms()) {
            JSONObject atom = new JSONObject();
            // CDK informations
            atom.put("cdk_idx", a);
            // Atom informations
            IAtom ia = cov.getChemicalObject().getMolecule().getAtom(a);
            atom.put("name", ia.getSymbol());
            atom.put("hydrogens", match.getHydrogensFrom(a));
            // Residue informations
            atom.put("res", match.getResidue().getId());
            atom.put("matchIdx", matchId);
            atoms.add(atom);
        }
        // Bonds
        for (int b : match.getBonds()) {
            IBond ib = cov.getChemicalObject().getMolecule().getBond(b);
            usedBonds.add(ib);
            JSONObject bond = new JSONObject();
            // CDK informations
            bond.put("cdk_idx", b);
            // atoms linked
            JSONArray linkedAtoms = new JSONArray();
            for (IAtom a : ib.atoms()) {
                linkedAtoms.add(cov.getChemicalObject().getMolecule().getAtomNumber(a));
            }
            bond.put("arity", ib.getOrder().numeric());
            bond.put("atoms", linkedAtoms);
            bond.put("res", match.getResidue().getId());
            bonds.add(bond);
        }
        matchId++;
    }
    IMolecule mol = cov.getChemicalObject().getMolecule();
    for (IBond ib : mol.bonds()) {
        if (!usedBonds.contains(ib)) {
            JSONObject bond = new JSONObject();
            // CDK informations
            bond.put("cdk_idx", mol.getBondNumber(ib));
            // atoms linked
            JSONArray linkedAtoms = new JSONArray();
            for (IAtom a : ib.atoms()) {
                linkedAtoms.add(mol.getAtomNumber(a));
            }
            bond.put("arity", ib.getOrder().numeric());
            bond.put("atoms", linkedAtoms);
            bonds.add(bond);
        }
    }
    return graph;
}
Also used : JSONObject(org.json.simple.JSONObject) IMolecule(org.openscience.cdk.interfaces.IMolecule) JSONArray(org.json.simple.JSONArray) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) HashSet(java.util.HashSet) Match(algorithms.utils.Match)

Example 3 with Match

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

the class ContractedGraph method initCoveredVerticies.

// Create nodes with covered atoms contracted
private void initCoveredVerticies(Coverage cov) {
    HashSet<Match> matches = cov.getUsedMatches();
    for (Match match : matches) {
        Vertex v = new Vertex();
        v.id = match.getId();
        v.res = match.getResidue();
        v.vertices.addAll(match.getAtoms());
        for (int id : match.getAtoms()) {
            this.verticiesOfatoms.put(id, v);
            if (match.getExtLinks().containsKey(id)) {
                v.kind.put(id, match.getExtLinks().get(id));
            }
        }
        this.addVertex(v);
    }
}
Also used : Match(algorithms.utils.Match)

Example 4 with Match

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

the class Modulation method getMatchOnUncoveredAtoms.

/**
 * Get ordered matches from uncovered parts.
 * The order depends on number on covering atoms and size of the matches
 * @param cov
 * @param contract
 * @param banned
 * @return
 */
private List<Match> getMatchOnUncoveredAtoms(Coverage cov, Set<Match> banned, Set<Integer> unmovable) {
    List<Match> matches = new ArrayList<>();
    Set<Integer> uncovered = new HashSet<>();
    for (int atomIdx : this.usedIndex.keySet()) {
        if (this.usedIndex.get(atomIdx).size() == 0)
            uncovered.add(atomIdx);
    }
    Map<Match, Integer> uncoveredByMatch = new HashMap<>();
    for (int idx : uncovered) {
        for (Match match : this.index.get(idx)) {
            if (banned.contains(match) || !Collections.disjoint(match.getAtoms(), unmovable))
                continue;
            int val = uncoveredByMatch.containsKey(match) ? uncoveredByMatch.get(match) : 0;
            uncoveredByMatch.put(match, val + 1);
            if (val == 0)
                matches.add(match);
        }
    }
    Collections.sort(matches, new ModulationComparator(uncoveredByMatch));
    return matches;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Match(algorithms.utils.Match) HashSet(java.util.HashSet)

Example 5 with Match

use of algorithms.utils.Match 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);
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) IAtom(org.openscience.cdk.interfaces.IAtom) 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