org.openscience.cdk.interfaces.IAtomContainer Java Examples

The following examples show how to use org.openscience.cdk.interfaces.IAtomContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CDKReactionBuilder.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void setReactantMolecule(IReaction IR, Collection<IAtomContainer> metabolites) {
//
//        System.out.println("-------------------");
//        System.out.println("Reactants");
//        System.out.println("-------------------");

        Iterator<IAtomContainer> it = metabolites.iterator();
        //System.out.println("Stoic Map Size: " + stoichiometryMap.size());

        while (it.hasNext()) {
            IAtomContainer mol = it.next();
//            System.out.println("Insertion: " + mol.getID() + ", " + stoichiometryMap.get(mol.getID()));
            mol.setProperty("STOICHIOMETRY", stoichiometryMap.get(mol.getID()));
            IR.addReactant(mol, stoichiometryMap.get(mol.getID()));
            //IR.setReactantCoefficient(mol,wt);
//            System.out.println("Reaction: " + mol.getID() + ", " + standardizedReaction.getProductCoefficient(mol));
        }

        metabolites.clear();
        stoichiometryMap.clear();
    }
 
Example #2
Source File: BaseGameTheory.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
synchronized MCSSolution copyOldSolutionToNew(int queryPosition, int targetPosition,
        IAtomContainer compound1, IAtomContainer compound2, MCSSolution oldSolution) {
    AtomAtomMapping atomAtomMapping = oldSolution.getAtomAtomMapping();
    Map<Integer, Integer> mappingsByIndex = atomAtomMapping.getMappingsByIndex();

    AtomAtomMapping atomAtomMappingNew = new AtomAtomMapping(compound1, compound2);
    mappingsByIndex.entrySet().forEach((m) -> {
        atomAtomMappingNew.put(compound1.getAtom(m.getKey()), compound2.getAtom(m.getValue()));
    });
    MCSSolution mcsSolution = new MCSSolution(queryPosition, targetPosition, compound1, compound2, atomAtomMappingNew);
    mcsSolution.setEnergy(oldSolution.getEnergy());
    mcsSolution.setFragmentSize(oldSolution.getFragmentSize());
    mcsSolution.setStereoScore(oldSolution.getStereoScore());

    return mcsSolution;
}
 
Example #3
Source File: SpectralMatchPanelFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private IAtomContainer parseSmiles(SpectralDBPeakIdentity hit) {
  SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
  String smilesString = hit.getEntry().getField(DBEntryField.SMILES).orElse("N/A").toString();
  IAtomContainer molecule;
  if (smilesString != "N/A") {
    try {
      molecule = smilesParser.parseSmiles(smilesString);
      return molecule;
    } catch (InvalidSmilesException e1) {
      String errorMessage = "Could not load 2D structure\n" + "Exception: ";
      logger.log(Level.WARNING, errorMessage, e1);
      return null;
    }
  } else {
    return null;
  }
}
 
Example #4
Source File: State.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
State(IQueryAtomContainer source, IAtomContainer target) {
    this.size = 0;
    this.sourceTerminalSize = 0;
    this.targetTerminalSize = 0;
    this.source = source;
    this.target = target;
    this.ownSharedState = true;
    this.matches = new boolean[this.source.getAtomCount()][this.target.getAtomCount()];
    this.isMatchPossible = isFeasible();

    this.lastAddition = new Pair<>(-1, -1);
    this.sharedState = new SharedState(source.getAtomCount(),
            target.getAtomCount());
    this.am = AtomMatcher.forQuery();
    this.bm = BondMatcher.forQuery();
}
 
Example #5
Source File: SpectralMatchPanel.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private IAtomContainer parseInChi(SpectralDBPeakIdentity hit) {
  String inchiString = hit.getEntry().getField(DBEntryField.INCHI).orElse("N/A").toString();
  InChIGeneratorFactory factory;
  IAtomContainer molecule;
  if (inchiString != "N/A") {
    try {
      factory = InChIGeneratorFactory.getInstance();
      // Get InChIToStructure
      InChIToStructure inchiToStructure =
          factory.getInChIToStructure(inchiString, DefaultChemObjectBuilder.getInstance());
      molecule = inchiToStructure.getAtomContainer();
      return molecule;
    } catch (CDKException e) {
      String errorMessage = "Could not load 2D structure\n" + "Exception: ";
      logger.log(Level.WARNING, errorMessage, e);
      return null;
    }
  } else {
    return null;
  }
}
 
Example #6
Source File: Reactor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param id
 * @param molSet
 * @return
 */
private synchronized List<IAtom> markHAroundCoreAtoms(String id, IAtomContainerSet molSet) {

    List<IAtom> list = new ArrayList<>();
    for (int pMol = 0; pMol < molSet.getAtomContainerCount(); pMol++) {
        IAtomContainer pMolecule = molSet.getAtomContainer(pMol);
        for (int pAtom = 0; pAtom < pMolecule.getAtomCount(); pAtom++) {
            IAtom atom = molSet.getAtomContainer(pMol).getAtom(pAtom);
            if (!atom.getSymbol().equalsIgnoreCase("H") && !atom.getID().equalsIgnoreCase("-1")) {
                if (atom.getID().equalsIgnoreCase(id)) {
                    List<IAtom> conAtoms = pMolecule.getConnectedAtomsList(atom);
                    conAtoms.stream().filter((atomH) -> (atomH.getID().equalsIgnoreCase("-1") && atomH.getSymbol().equalsIgnoreCase("H"))).forEach((atomH) -> {
                        list.add(atomH);
                    });
                }
            }
        }
    }
    return list;
}
 
Example #7
Source File: BEMatrix.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @throws CDKException
 */
void setMatrixAtoms() throws CDKException {
    //System.out.println("H " + withoutH);
    initMatrix(0.);
    atomArray.clear();
    for (IAtomContainer container : myMoleculeSet.atomContainers()) {
        for (IAtom atom : container.atoms()) {
            if (withoutH && atom.getSymbol().matches("H")) {
                continue;
            }
            if (!mappings.containsKey(atom) && !mappings.containsValue(atom)) {
                continue;
            }
            atomArray.add(atom);
        }
    }
    setMatrix();
}
 
Example #8
Source File: Chirality2DTool.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param stereoElement
 * @param atomContainer
 * @return
 */
public static IStereoAndConformation getChirality2D(
        IStereoElement stereoElement, IAtomContainer atomContainer) {
    if (stereoElement instanceof ITetrahedralChirality) {
        CIP_CHIRALITY chiral = getCIPChirality(
                atomContainer, (ITetrahedralChirality) stereoElement);
        switch (chiral) {
            case NONE:
                return NONE;
            case R:
                return R;
            case S:
                return S;
            default:
                return NONE;
        }
    } else {
        return NONE;
    }
}
 
Example #9
Source File: Structure2DComponent.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public Structure2DComponent(IAtomContainer container, Font font) throws CDKException {
  molecule = container;

  // Suppress the hydrogens
  AtomContainerManipulator.suppressHydrogens(molecule);

  // If the model has no coordinates, let's generate them
  if (!GeometryUtil.has2DCoordinates(molecule)) {
    StructureDiagramGenerator sdg = new StructureDiagramGenerator();
    sdg.setMolecule(molecule, false);
    sdg.generateCoordinates();
  }

  // Generators make the image elements
  List<IGenerator<IAtomContainer>> generators = new ArrayList<IGenerator<IAtomContainer>>();
  generators.add(new BasicSceneGenerator());
  generators.add(new StandardGenerator(font));

  // Renderer needs to have a toolkit-specific font manager
  renderer = new AtomContainerRenderer(generators, new AWTFontManager());

  // Set default atom colors for the renderer
  RendererModel rendererModel = renderer.getRenderer2DModel();
  rendererModel.set(StandardGenerator.AtomColor.class, new CDK2DAtomColors());
}
 
Example #10
Source File: MDLV2000Writer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Writes a {@link IChemObject} to the MDL molfile formated output. It can
 * only output ChemObjects of type {@link IChemFile},
 * {@link IChemObject} and {@link IAtomContainer}.
 *
 * @param object {@link IChemObject} to write
 * @see #accepts(Class)
 */
@Override
public void write(IChemObject object) throws CDKException {
    customizeJob();
    try {
        if (object instanceof IChemFile) {
            writeChemFile((IChemFile) object);
            return;
        } else if (object instanceof IChemModel) {
            IChemFile file = object.getBuilder().newInstance(IChemFile.class);
            IChemSequence sequence = object.getBuilder().newInstance(IChemSequence.class);
            sequence.addChemModel((IChemModel) object);
            file.addChemSequence(sequence);
            writeChemFile((IChemFile) file);
            return;
        } else if (object instanceof IAtomContainer) {
            writeMolecule((IAtomContainer) object);
            return;
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        logger.debug(ex);
        throw new CDKException("Exception while writing MDL file: " + ex.getMessage(), ex);
    }
    throw new CDKException("Only supported is writing of IChemFile, " + "IChemModel, and IAtomContainer objects.");
}
 
Example #11
Source File: MCSTest.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
    public void test_BIG_count() throws Exception {
        ////////System.out.println("3");
        SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());

        IAtomContainer query = sp.parseSmiles("C\\C1=C2\\N\\C(=C/C3=N/C(=C\\C4=C(CC(O)=O)C(CCC(O)=O)=C(CC5=C(CCC(O)=O)C(CC(O)=O)=C1N5)N4)/[C@@H](CCC(O)=O)[C@]3(C)CC(O)=O)[C@@H](CCC(O)=O)[C@]2(C)CC(O)=O");
        IAtomContainer target = sp.parseSmiles("C[C@]1(CC(O)=O)[C@H](CCC(O)=O)\\C2=C\\C3=C(CC(O)=O)C(CCC(O)=O)=C(CC4=C(CCC(O)=O)C(CC(O)=O)=C(N4)[C@](C)(O)[C@@]45N\\C(=C/C1=N2)[C@@H](CCC(O)=O)[C@]4(C)CC(=O)O5)N3");
        MoleculeInitializer.initializeMolecule(query);
        MoleculeInitializer.initializeMolecule(target);

        org.openscience.smsd.algorithm.matchers.AtomMatcher atomMatcher = AtomBondMatcher.atomMatcher(false, false);
        org.openscience.smsd.algorithm.matchers.BondMatcher bondMatcher = AtomBondMatcher.bondMatcher(false, false);

//        org.openscience.smsd.algorithm.mcsplus.MCSPlusMapper mcs
//                = new org.openscience.smsd.algorithm.mcsplus.MCSPlusMapper(query, target, atomMatcher, bondMatcher);
        Isomorphism mcs
                = new Isomorphism(query, target, Algorithm.VFLibMCS, atomMatcher, bondMatcher);
        String create = new SmilesGenerator(SmiFlavor.Canonical).create(mcs.getFirstAtomMapping().getMapCommonFragmentOnQuery());
//        System.out.println("MCS " + create);
        assertEquals(63, mcs.getFirstAtomMapping().getCount());

    }
 
Example #12
Source File: MCSTest.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
    public void MCSRingCheck() throws Exception {
        ////////System.out.println("3");
        SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
        IAtomContainer query = sp.parseSmiles("OC[C@H]1OC[C@H](O)[C@@H](O)[C@@H]1O");
        IAtomContainer target = sp.parseSmiles("OC[C@H]1O[C@H](O[C@H]2O[C@H](CO)[C@@H](O)[C@H](O)[C@H]2O)[C@H](O)[C@@H](O)[C@@H]1O");

        MoleculeInitializer.initializeMolecule(query);
        MoleculeInitializer.initializeMolecule(target);

        org.openscience.smsd.algorithm.matchers.AtomMatcher atomMatcher = AtomBondMatcher.atomMatcher(false, false);
        org.openscience.smsd.algorithm.matchers.BondMatcher bondMatcher = AtomBondMatcher.bondMatcher(false, false);

        Isomorphism mcs
                = new Isomorphism(query, target, Algorithm.DEFAULT, atomMatcher, bondMatcher);

//            org.openscience.smsd.algorithm.mcsplus.MCSPlusMapper mcs
//                    = new org.openscience.smsd.algorithm.mcsplus.MCSPlusMapper(query, target, false, false, false);
//        System.out.println("mcs " + mcs.getFirstAtomMapping().getCommonFragmentAsSMILES());
        assertEquals(11, mcs.getFirstAtomMapping().getCount());

    }
 
Example #13
Source File: RBlastSmilesGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Append the symbol for the bond order between <code>a1</code> and
 * <code>a2</code> to the <code>line</code>.
 *
 * @param line the StringBuffer that the bond symbol is appended to.
 * @param a1 Atom participating in the bond.
 * @param a2 Atom participating in the bond.
 * @param atomContainer the GraphAtomContainer that the SMILES string is
 * generated for.
 * @param useAromaticity true=aromaticity or sp2 will trigger lower case
 * letters, wrong=only sp2
 */
private void parseBond(StringBuffer line, IAtom a1, IAtom a2, IAtomContainer atomContainer, boolean useAromaticity) {
    //LOGGER.debug("in parseBond()");
    if (useAromaticity && a1.getFlag(ISAROMATIC) && a2.getFlag(ISAROMATIC)) {
        return;
    }
    if (atomContainer.getBond(a1, a2) == null) {
        return;
    }
    IBond.Order type = atomContainer.getBond(a1, a2).getOrder();
    if (null != type) {
        switch (type) {
            case SINGLE:
                break;
            case DOUBLE:
                line.append("=");
                break;
            case TRIPLE:
                line.append("#");
                break;
            // //LOGGER.debug("Unknown bond type");
            default:
                break;
        }
    }
}
 
Example #14
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param ringBond
 * @param singleRings
 * @return
 */
public static int getNeighbourBondOrderCountFromRing(IBond ringBond, IRingSet singleRings) {
    int minValue = 9999;
    for (IAtomContainer ring : singleRings.atomContainers()) {
        int value = 0;
        if (ring.contains(ringBond.getAtom(0)) && ring.contains(ringBond.getAtom(1))) {
            for (IBond bond : ring.bonds()) {
                if (bond.contains(ringBond.getAtom(0)) || bond.contains(ringBond.getAtom(1))) {
                    value += bond.getOrder().numeric();
                }
            }
        }
        if (value < minValue) {
            minValue = value;
        }
    }
    return minValue;
}
 
Example #15
Source File: WedgeStereoAnalyser.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static WedgeStereoAnalysisResult getResult(IAtomContainer atomContainer, boolean isPotentialStereoCenter, IStereoElement stereoElement) {
    if (isPotentialStereoCenter) {
        if (stereoElement == null) {
            return MISSING;
        } else {
            IStereoAndConformation chirality = getChirality2D(stereoElement, atomContainer);
            WedgeStereoAnalysisResult result = convertCipToResult(chirality);
            if (result == NONE) {
                // should have R or S!
                return ERROR;
            } else {
                return result;
            }
        }
    } else if (stereoElement == null) {
        return NONE;
    } else {
        return ERROR;
    }
}
 
Example #16
Source File: AbstractAWTReactionLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     *
     * @param molSet
     * @param molSetBoundsTree
     * @param dx
     * @param dy
     */
    public void shiftMoleculeSet(IAtomContainerSet molSet,
            BoundsTree molSetBoundsTree, double dx, double dy) {
//        System.out.println(molSetBoundsTree);
        int counter = 0;
        for (IAtomContainer molecule : molSet.atomContainers()) {
            String molLabel = molSet.getID() + "_" + molecule.getID() + ":" + counter;
//            System.out.println("shifting " + molLabel + " from " + BoundsPrinter.toString(GeometryTools.getRectangle2D(molecule)));
            Rectangle2D bounds = molSetBoundsTree.get(molLabel);
            bounds.setFrame(bounds.getMinX() + dx, bounds.getMinY() + dy,
                    bounds.getWidth(), bounds.getHeight());
            translate2D(molecule, dx, dy);
//            System.out.println("shifting " + molecule.getID() + " to " + BoundsPrinter.toString(GeometryTools.getRectangle2D(molecule)));
            counter++;
        }
    }
 
Example #17
Source File: CDKMCS.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the first isomorph 'atom mapping' found for g2 in g1.
 *
 * @param g1 first molecule. Must not be an {@link IQueryAtomContainer}.
 * @param g2 second molecule. May be an {@link IQueryAtomContainer}.
 * @param shouldMatchBonds
 * @param shouldMatchRings
 * @param matchAtomType
 * @return the first isomorph atom mapping found projected on g1. This is a
 * List of CDKRMap objects containing Ids of matching atoms.
 * @throws CDKException if the first molecules is not an instance of
 * {@link IQueryAtomContainer}
 */
private static List<CDKRMap> getIsomorphAtomsMap(IAtomContainer g1, IAtomContainer g2,
        AtomMatcher am, BondMatcher bm) throws CDKException {
    if (g1 instanceof IQueryAtomContainer) {
        throw new CDKException(
                "The first IAtomContainer must not be an IQueryAtomContainer");
    }

    List<CDKRMap> list = checkSingleAtomCases(g1, g2);
    if (list == null) {
        return makeAtomsMapOfBondsMap(getIsomorphMap(g1, g2, am, bm), g1, g2);
    } else if (list.isEmpty()) {
        return null;
    } else {
        return list;
    }
}
 
Example #18
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Used CDK to generate smiles
 *
 * @param mol
 * @param remove_AAM
 * @return
 */
public static String getSMILES(
        IAtomContainer mol, boolean remove_AAM) {
    String smiles = "";
    try {
        return new CDKSMILES(mol, true, remove_AAM).getCanonicalSMILES();
    } catch (CloneNotSupportedException ex) {
        LOGGER.error(SEVERE, null, ex);
    }
    return smiles;
}
 
Example #19
Source File: Reactor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private synchronized IAtom getContainerAtomByID(IAtomContainerSet products, String mappingID) {
    for (IAtomContainer ac : products.atomContainers()) {
        for (IAtom atom : ac.atoms()) {
            if (atom.getID().equals(mappingID)) {
                return atom;
            }
        }
    }
    return null;
}
 
Example #20
Source File: DirectAtomDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Map<IAtom, Integer> getLonePairCounts(IAtomContainer atomContainer) {
    Map<IAtom, Integer> lonePairMap = new HashMap<>();
    for (ILonePair lonePair : atomContainer.lonePairs()) {
        IAtom atom = lonePair.getAtom();
        int lonePairCount;
        if (lonePairMap.containsKey(atom)) {
            lonePairCount = lonePairMap.get(atom);
        } else {
            lonePairCount = 0;
        }
        lonePairMap.put(atom, lonePairCount + 1);
    }
    return lonePairMap;
}
 
Example #21
Source File: FragmentFilter.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private synchronized int getMappedMoleculeFragmentSize(AtomAtomMapping mcsAtomSolution) {

        IAtomContainer Educt = SilentChemObjectBuilder.getInstance().newInstance(IAtomContainer.class, chemfilter.getQuery());
        IAtomContainer product = SilentChemObjectBuilder.getInstance().newInstance(IAtomContainer.class, chemfilter.getTarget());

        if (mcsAtomSolution != null) {
            mcsAtomSolution.getMappingsByAtoms().entrySet().stream().forEach((map) -> {
                IAtom atomE = map.getKey();
                IAtom atomP = map.getValue();
                Educt.removeAtom(atomE);
                product.removeAtom(atomP);
            });
        }
        return getFragmentCount(Educt) + getFragmentCount(product);
    }
 
Example #22
Source File: MolContainer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param key
 * @param mol
 * @return
 * @throws Exception
 */
@Override
public synchronized boolean compareAtomContainer(String key, IAtomContainer mol) throws Exception {
    mol = removeHydrogensExceptSingleAndPreserveAtomID(mol);
    try {
        boolean flag = molContainer.containsKey(key);
        if (flag && mol.getAtomCount() > 0) {
            IAtomContainer molFromContainer = molContainer.get(key);
            return isIdentical(mol, molFromContainer, true);
        }
    } catch (Exception ex) {
        LOGGER.error(SEVERE, null, ex);
    }
    return false;
}
 
Example #23
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Return atom by ID match
 *
 * @param molWithoutH
 * @param refAtom
 * @return
 */
protected static int getAtomIndexByID(IAtomContainer molWithoutH, IAtom refAtom) {
    for (IAtom atom : molWithoutH.atoms()) {
        if (atom.getID().equalsIgnoreCase(refAtom.getID())) {
            return molWithoutH.indexOf(atom);
        }
    }
    return -1;
}
 
Example #24
Source File: SignatureMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param container
 * @return
 */
@Override
public IAtomContainer getCanonicalMolecule(IAtomContainer container) {
    try {
        IAtomContainer permute = container.clone();

        if (container.getID() != null) {
            permute.setID(container.getID());
        }

        for (int i = 0; i < permute.getAtomCount(); i++) {
            if (container.getAtom(i).getID() != null) {
                permute.getAtom(i).setID(container.getAtom(i).getID());
            }
        }

        int[] canonicalPermutation = getCanonicalPermutation(permute);

        permuteWithoutClone(canonicalPermutation, permute);

        return permute;
    } catch (CloneNotSupportedException ex) {
        LOGGER.error(SEVERE, null, ex);
    }

    return null;
}
 
Example #25
Source File: TargetProcessor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean unMappedAtomsEqualsIndexI(
            IAtomContainer target,
            int mappingSize,
            int atomIndex,
            int counter,
            List<Integer> mapped_atoms,
            Integer indexI,
            Integer indexJ,
            Integer order) {
        boolean normal_bond = true;
        for (int c = 0; c < mappingSize; c++) {
            if (mapped_atoms.get(c * 2 + 1).equals(indexJ)) {
                setBondNeighbors(indexI, indexJ, order);
                if (cTab2Copy.get(atomIndex * 4 + 3).compareToIgnoreCase("X") == 0) {
                    step1(atomIndex, counter);
                    McGregorChecks.changeCharBonds(indexJ, signArray[counter], target.getBondCount(),
                            target, cTab2Copy);
                    int cor_atom = McGregorChecks.searchCorrespondingAtom(mappingSize, indexJ, 2, mapped_atoms);
                    //Commented by Asad
                    McGregorChecks.changeCharBonds(cor_atom, signArray[counter], newNeighborNumA,
                            newINeighborsA, newCNeighborsA);
//                                changeCharBonds(cor_atom, signArray[counter], query.getBondCount(), query, cTab1Copy);
                    counter++;
                } else {
                    step2(atomIndex);
                }
                normal_bond = false;
                neighborBondNumB++;
            }
        }
        return normal_bond;
    }
 
Example #26
Source File: AbstractDirectLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param atomContainer
 * @param molAxis
 */
public void align(IAtomContainer atomContainer, Vector2d molAxis) {
    switch (params.moleculeAlignMethod) {
        case MAX_AXIS: alignToMaxWidth(atomContainer, molAxis);
        case MIN_AREA: alignToMinAreaBox(atomContainer, molAxis);
        default: alignToMaxWidth(atomContainer, molAxis);
    }
}
 
Example #27
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * ac1 is subgraph of ac2
 *
 * @param source
 * @param target
 * @param matchBonds
 * @param shouldMatchRings
 * @param matchAtomType
 * @param matchRingSize
 * @return
 * @throws org.openscience.cdk.exception.CDKException
 */
public static Map<IAtom, IAtom> findSubgraph(
        IAtomContainer source, IAtomContainer target,
        boolean matchAtomType, boolean matchBonds, boolean shouldMatchRings,
        boolean matchRingSize) throws CDKException {

    ExtAtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(source);
    MoleculeInitializer.initializeMolecule(source);

    ExtAtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(target);
    MoleculeInitializer.initializeMolecule(target);

    AtomMatcher atomMatcher = AtomBondMatcher.atomMatcher(matchAtomType, matchRingSize);
    BondMatcher bondMatcher = AtomBondMatcher.bondMatcher(matchBonds, shouldMatchRings);

    Substructure s;
    if (source.getAtomCount() <= target.getAtomCount()) {
        try {
            s = new Substructure(source, target, atomMatcher, bondMatcher, false);
            s.setChemFilters(true, true, true);
            return s.getFirstAtomMapping().getMappingsByAtoms();
        } catch (CDKException ex) {
            Logger.getLogger(uk.ac.ebi.reactionblast.mechanism.helper.Utility.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return new HashMap<>();
}
 
Example #28
Source File: BondChangeCalculator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private int chipTheBondCountSmallestFragmentSize(IAtomContainer cloneContainer, int chippedBondIndex) {
    int size = cloneContainer.getAtomCount();
    cloneContainer.removeBond(chippedBondIndex);
    boolean fragmentFlag = isConnected(cloneContainer);
    if (!fragmentFlag) {
        IAtomContainerSet partitionIntoMolecules = partitionIntoMolecules(cloneContainer);
        for (IAtomContainer ac : partitionIntoMolecules.atomContainers()) {
            if (size > ac.getAtomCount()) {
                size = ac.getAtomCount();
            }
        }
    }
    return size;
}
 
Example #29
Source File: QueryProcessor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
     *
     * @param query
     * @param target
     * @param unmapped_atoms_molA
     * @param mapped_atoms
     * @param counter
     */
    protected void process(
            IQueryAtomContainer query,
            IAtomContainer target,
            List<Integer> unmapped_atoms_molA,
            List<Integer> mapped_atoms,
            int counter) {

        int unmapped_numA = unmapped_atoms_molA.size();

//        System.out.println("\n" + cTab1Copy + "\n");
        for (int atomIndex = 0; atomIndex < query.getBondCount(); atomIndex++) {
            Integer indexI = query.indexOf(query.getBond(atomIndex).getAtom(0));
            Integer indexJ = query.indexOf(query.getBond(atomIndex).getAtom(1));
            Integer order = 0;
            if (query.getBond(atomIndex).getOrder() != null) {
                order = query.getBond(atomIndex).getOrder().numeric();
            }

            boolean bond_considered = false;
            boolean normal_bond = true;

//            System.out.println(AtomI + "= , =" + AtomJ );
            for (Integer unMappedAtomIndex = 0; unMappedAtomIndex < unmapped_numA; unMappedAtomIndex++) {

                if (unmapped_atoms_molA.get(unMappedAtomIndex).equals(indexI)) {
                    normal_bond = unMappedAtomsEqualsIndexJ(query, target, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
                    bond_considered = true;
                } else //Does a ungemaptes atom at second position in the connection occur?
                if (unmapped_atoms_molA.get(unMappedAtomIndex).equals(indexJ)) {
                    normal_bond = unMappedAtomsEqualsIndexI(query, target, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
                    bond_considered = true;
                }
                if (normal_bond && bond_considered) {
                    markNormalBonds(atomIndex, indexI, indexJ, order);
                    break;
                }
            }
        }
    }
 
Example #30
Source File: ChiralityComparisonTool.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param atomContainerA
 * @param atomContainerB
 * @throws Exception
 */
public static void compare(IAtomContainer atomContainerA, IAtomContainer atomContainerB) throws Exception {
    Map<IAtom, IStereoAndConformation> chiralityMapA;
    if (has3DCoordinates(atomContainerA)) {
        chiralityMapA = new Chirality3DTool().getTetrahedralChiralities(atomContainerA);
    } else {
        chiralityMapA = new Chirality2DTool().getTetrahedralChiralities(atomContainerA);
    }

    Map<IAtom, IStereoAndConformation> chiralityMapB;
    if (has3DCoordinates(atomContainerB)) {
        chiralityMapB = new Chirality3DTool().getTetrahedralChiralities(atomContainerB);
    } else {
        chiralityMapB = new Chirality2DTool().getTetrahedralChiralities(atomContainerB);
    }

    AtomMatcher atomMatcher = AtomBondMatcher.atomMatcher(false, false);
    BondMatcher bondMatcher = AtomBondMatcher.bondMatcher(true, false);

    Isomorphism isomorphism = new Isomorphism(atomContainerA, atomContainerB, DEFAULT, atomMatcher, bondMatcher);
    Map<IAtom, IAtom> atomMap = isomorphism.getFirstAtomMapping().getMappingsByAtoms();
    atomMap.keySet().stream().forEach((atomA) -> {
        IAtom atomB = atomMap.get(atomA);
        boolean isStereoA = chiralityMapA.containsKey(atomA);
        boolean isStereoB = chiralityMapB.containsKey(atomB);
        if (isStereoA && isStereoB) {
            IStereoAndConformation stereoA = chiralityMapA.get(atomA);
            IStereoAndConformation stereoB = chiralityMapB.get(atomB);
            out.println(stereoA + " " + stereoB);
        }
    });
}