/** * * @param reaction * @return a new mol with explicit Hydrogens * @throws CloneNotSupportedException */ public static IReaction addExplicitH(IReaction reaction) throws CloneNotSupportedException { IReaction r = reaction.getBuilder().newInstance(IReaction.class); for (IAtomContainer ac : reaction.getReactants().atomContainers()) { IAtomContainer addExplicitH = ExtAtomContainerManipulator.addExplicitH(ac); r.addReactant(addExplicitH, reaction.getReactantCoefficient(ac)); } for (IAtomContainer ac : reaction.getProducts().atomContainers()) { IAtomContainer addExplicitH = ExtAtomContainerManipulator.addExplicitH(ac); r.addProduct(addExplicitH, reaction.getProductCoefficient(ac)); } r.setDirection(reaction.getDirection()); r.setID(reaction.getID() == null ? "" : reaction.getID()); return r; } }
private double caclModelScale(IReaction rxn) { List<IAtomContainer> mols = new ArrayList<>(); for (IAtomContainer mol : rxn.getReactants().atomContainers()) mols.add(mol); for (IAtomContainer mol : rxn.getProducts().atomContainers()) mols.add(mol); for (IAtomContainer mol : rxn.getAgents().atomContainers()) mols.add(mol); return caclModelScale(mols); }
private synchronized void BondCollection() { for (int i = 0; i < reactionWithUniqueSTOICHIOMETRY.getReactantCount(); i++) { IAtomContainer mol = reactionWithUniqueSTOICHIOMETRY.getReactants().getAtomContainer(i); for (int j = 0; j < mol.getBondCount(); j++) { IBond bond = mol.getBond(j); rBonds.add(bond); } } for (int i = 0; i < reactionWithUniqueSTOICHIOMETRY.getProductCount(); i++) { IAtomContainer mol = reactionWithUniqueSTOICHIOMETRY.getProducts().getAtomContainer(i); for (int j = 0; j < mol.getBondCount(); j++) { IBond bond = mol.getBond(j); pBonds.add(bond); } } }
public void setChemObject(IChemObject object) { if (object instanceof IReaction) { source = object; // update table contents IReaction reaction = (IReaction)source; idField.setText(reaction.getID()); //TODO //directionField.setSelectedIndex(reaction.getDirection()); solventField.setText((String)reaction.getProperty(SOLVENT)); tempField.setText((String)reaction.getProperty(TEMPERATURE)); } else { throw new IllegalArgumentException("Argument must be an Reaction"); } }
@Override public IReaction getCanonicalReaction(IReaction reaction) { BlockMapping blockMapping = new BlockMapping(reaction); // printReaction(reaction); builder = reaction.getBuilder(); IReaction permutedReaction = builder.newInstance(IReaction.class); IAtomContainerSet reactants = reaction.getReactants(); IAtomContainerSet permutedReactants = permuteR(reactants, blockMapping); permutedReaction.setReactants(permutedReactants); IAtomContainerSet products = reaction.getProducts(); IAtomContainerSet permutedProducts = permuteP(products, blockMapping); permutedReaction.setProducts(permutedProducts); replaceMappings(reaction, permutedReaction); permutedReaction.setID(reaction.getID()); return permutedReaction; }
private IReaction layoutReaction( IReaction mappedReaction, String reactionID) { IReaction reactionWithLayout = new Reaction(); reactionWithLayout.setDirection(FORWARD); reactionWithLayout.setID(reactionID); for (IAtomContainer ac : mappedReaction.getReactants().atomContainers()) { IAtomContainer moleculeWithLayoutCheck = getMoleculeWithLayoutCheck(ac); moleculeWithLayoutCheck.setID(ac.getID()); reactionWithLayout.addReactant(ac, mappedReaction.getReactantCoefficient(ac)); } for (IAtomContainer ac : mappedReaction.getProducts().atomContainers()) { IAtomContainer moleculeWithLayoutCheck = getMoleculeWithLayoutCheck(ac); moleculeWithLayoutCheck.setID(ac.getID()); reactionWithLayout.addProduct(ac, mappedReaction.getProductCoefficient(ac)); } for (IMapping m : mappedReaction.mappings()) { reactionWithLayout.addMapping(m); } reactionWithLayout.setFlags(mappedReaction.getFlags()); reactionWithLayout.setProperties(mappedReaction.getProperties()); return reactionWithLayout; }
public static IAtomContainer getRelevantAtomContainer(IReaction reaction, IBond bond) { IAtomContainer result = MoleculeSetManipulator.getRelevantAtomContainer(reaction.getReactants(), bond); if (result != null) { return result; } return MoleculeSetManipulator.getRelevantAtomContainer(reaction.getProducts(), bond); }
protected static String cansmi(IReaction rxn) throws CDKException { IReaction copy = rxn.getBuilder().newInstance(IReaction.class); for (IAtomContainer mol : rxn.getReactants().atomContainers()) copy.addReactant(AtomContainerManipulator.copyAndSuppressedHydrogens(mol)); for (IAtomContainer mol : rxn.getProducts().atomContainers()) copy.addProduct(AtomContainerManipulator.copyAndSuppressedHydrogens(mol)); for (IAtomContainer mol : rxn.getAgents().atomContainers()) copy.addAgent(AtomContainerManipulator.copyAndSuppressedHydrogens(mol)); return smigen.create(copy); }
protected IReaction convertRoundTripRXNSMILES(IReaction r) throws CDKException { final SmilesGenerator sg = new SmilesGenerator( SmiFlavor.AtomAtomMap | SmiFlavor.UseAromaticSymbols | SmiFlavor.Stereo); String createSmilesFromReaction = sg.create(r); final SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IReaction parseReactionSmiles = smilesParser.parseReactionSmiles(createSmilesFromReaction); parseReactionSmiles.setID(r.getID()); for (int i = 0; i < r.getReactantCount(); i++) { parseReactionSmiles.getReactants().getAtomContainer(i).setID(r.getReactants().getAtomContainer(i).getID()); } for (int i = 0; i < r.getProductCount(); i++) { parseReactionSmiles.getProducts().getAtomContainer(i).setID(r.getProducts().getAtomContainer(i).getID()); } return parseReactionSmiles; }
try { IReaction reaction = DefaultChemObjectBuilder.getInstance().newInstance(IReaction.class); reaction.addReactant(getQuery().clone(), 1.0); reaction.addProduct(getTarget().clone(), 1.0); for (IAtomContainer ac : reaction.getReactants().atomContainers()) { for (IAtom a : ac.atoms()) { IAtom refAtom = getQuery().getAtom(ac.getAtomNumber(a)); IAtom mappedAtom = mapping.get(refAtom); int mappedAtomIndex = getTarget().getAtomNumber(mappedAtom); IAtom b = reaction.getProducts().getAtomContainer(0).getAtom(mappedAtomIndex); b.setProperty(ATOM_ATOM_MAPPING, counter); b.setFlag(MAPPED, true); IMapping aammapping = reaction.getBuilder().newInstance(IMapping.class, a, b); reaction.addMapping(aammapping);
IAtomContainerSet reactants = reaction.getReactants(); IAtomContainerSet products = reaction.getProducts(); fillMap(reactants, atomIDLookup, "R"); fillMap(products, atomIDLookup, "P"); IChemObjectBuilder builder = reaction.getBuilder(); for (IMapping mapping : reaction.mappings()) { int count = reaction.getMappingCount(); for (int i = count; i > 0; i--) { reaction.removeMapping(i); reaction.addMapping(mapping); return mapping; }).map((_item) -> 1).reduce(numberOfMappingsAdded, Integer::sum);// System.out.println(numberOfMappingsAdded + " mappings added");
@Test public void fragmentGroupingReactants() throws InvalidSmilesException { IReaction reaction = smipar.parseReactionSmiles("CC1=NC2=C(O)C=CC=C2C=C1.CC(Cl)=O.[Al+3].[Cl-].[Cl-].[Cl-]>[O-][N+](=O)C1=CC=CC=C1>CC(=O)C1=C2C=CC(C)=NC2=C(O)C=C1 |f:2.3.4.5|"); assertThat(reaction.getReactantCount(), is(3)); assertThat(reaction.getAgents().getAtomContainerCount(), is(1)); assertThat(reaction.getProductCount(), is(1)); assertThat(reaction.getProperty(CDKConstants.TITLE, String.class), is("")); }
int globalIndex = fillIndexMap(indexMap, permutedReaction.getReactants(), 0); fillIndexMap(indexMap, permutedReaction.getProducts(), globalIndex); for (IMapping mapping : reaction.mappings()) { IAtom a0 = (IAtom) mapping.getChemObject(0); IAtom a1 = (IAtom) mapping.getChemObject(1); permutedReaction.addMapping(mappingMap.get(key)); permutedReaction.addMapping(mapping);
@Test public void testRoundtrip() throws Exception { IReaction reaction = builder.newInstance(IReaction.class); IAtomContainer hydroxide = builder.newInstance(IAtomContainer.class); hydroxide.addAtom(builder.newInstance(IAtom.class, "O")); reaction.addReactant(hydroxide); IAtomContainer proton = builder.newInstance(IAtomContainer.class); proton.addAtom(builder.newInstance(IAtom.class, "H")); reaction.addReactant(proton); IAtomContainer water = builder.newInstance(IAtomContainer.class); water.addAtom(builder.newInstance(IAtom.class, "O")); reaction.addProduct(water); reaction.addMapping(new Mapping(hydroxide.getAtom(0), water.getAtom(0))); // now serialize to MDL RXN StringWriter writer = new StringWriter(10000); String file = ""; MDLRXNWriter mdlWriter = new MDLRXNWriter(writer); mdlWriter.write(reaction); mdlWriter.close(); file = writer.toString(); Assert.assertTrue(file.length() > 0); // now deserialize the MDL RXN output IReaction reaction2 = builder.newInstance(IReaction.class); MDLRXNReader reader = new MDLRXNReader(new StringReader(file)); reaction2 = (IReaction) reader.read(reaction2); reader.close(); Assert.assertEquals(2, reaction2.getReactantCount()); Assert.assertEquals(1, reaction2.getProductCount()); Assert.assertEquals(1, reaction2.getMappingCount()); }
public static List<String> getAllIDs(IReaction reaction) { List<String> idList = new ArrayList<String>(); if (reaction.getID() != null) idList.add(reaction.getID()); IAtomContainerSet reactants = reaction.getReactants(); for (int i = 0; i < reactants.getAtomContainerCount(); i++) { IAtomContainer mol = reactants.getAtomContainer(i); idList.addAll(AtomContainerManipulator.getAllIDs(mol)); } IAtomContainerSet products = reaction.getProducts(); for (int i = 0; i < products.getAtomContainerCount(); i++) { IAtomContainer mol = products.getAtomContainer(i); idList.addAll(AtomContainerManipulator.getAllIDs(mol)); } return idList; }
@Test public void testGetAllProducts_IReaction() { IReaction reaction = builder.newInstance(IReaction.class); reaction.addReactant(builder.newInstance(IAtomContainer.class)); reaction.addReactant(builder.newInstance(IAtomContainer.class)); reaction.addReactant(builder.newInstance(IAtomContainer.class)); reaction.addProduct(builder.newInstance(IAtomContainer.class)); reaction.addProduct(builder.newInstance(IAtomContainer.class)); Assert.assertEquals(3, ReactionManipulator.getAllReactants(reaction).getAtomContainerCount()); }
@Test public void testGetReactants() { IReaction reaction = (IReaction) newChemObject(); IAtomContainer sodiumhydroxide = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer aceticAcid = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer water = reaction.getBuilder().newInstance(IAtomContainer.class); reaction.addReactant(sodiumhydroxide); reaction.addReactant(aceticAcid); reaction.addReactant(water); Assert.assertEquals(3, reaction.getReactants().getAtomContainerCount()); }
/** * A unit test suite for JUnit. Test of mapped IAtoms * * @return The test suite */ @Test public void testGetMappedChemObject_IReaction_IAtom() throws Exception { IReaction reaction = builder.newInstance(IReaction.class); IAtomContainer reactant = (new SmilesParser(builder)).parseSmiles("[C+]-C=C"); IAtomContainer product = (new SmilesParser(builder)).parseSmiles("C=C=C"); IMapping mapping = builder.newInstance(IMapping.class, reactant.getAtom(0), product.getAtom(0)); reaction.addMapping(mapping); mapping = builder.newInstance(IMapping.class, reactant.getAtom(1), product.getAtom(1)); reaction.addMapping(mapping); mapping = builder.newInstance(IMapping.class, reactant.getAtom(2), product.getAtom(2)); reaction.addMapping(mapping); reaction.addReactant(reactant); reaction.addProduct(product); IAtom mappedAtom = (IAtom) ReactionManipulator.getMappedChemObject(reaction, reactant.getAtom(0)); Assert.assertEquals(mappedAtom, product.getAtom(0)); mappedAtom = (IAtom) ReactionManipulator.getMappedChemObject(reaction, product.getAtom(1)); Assert.assertEquals(mappedAtom, reactant.getAtom(1)); }
@Test public void testGetProducts() { IReaction reaction = (IReaction) newChemObject(); IAtomContainer sodiumhydroxide = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer aceticAcid = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer water = reaction.getBuilder().newInstance(IAtomContainer.class); reaction.addProduct(sodiumhydroxide); reaction.addProduct(aceticAcid); reaction.addProduct(water); Assert.assertEquals(3, reaction.getProducts().getAtomContainerCount()); }
@Test public void noProducts() throws Exception { IReaction reaction = sp.parseReactionSmiles("C>>"); Assert.assertEquals(1, reaction.getReactantCount()); Assert.assertEquals(0, reaction.getProductCount()); }