/** * * @param reaction * @param atomAtomMap * @return */ protected List<IMapping> cloneMappings( IReaction reaction, Map<IAtom, IAtom> atomAtomMap) { // clone the mappings int numberOfMappings = reaction.getMappingCount(); List<IMapping> map = new ArrayList<>(); for (int mappingIndex = 0; mappingIndex < numberOfMappings; mappingIndex++) { IMapping mapping = reaction.getMapping(mappingIndex); map.add(cloneMapping(mapping, atomAtomMap)); } return map; }
/** * * @param reaction * @return */ public List<BlockPair> createBlockPairs(IReaction reaction) { List<BlockPair> blockPairs = new ArrayList<>(); calculateConnectedComponents().stream().map((mappingComponent) -> { // all components have at least one member DefinedMapping aMapping = mappingComponent.get(0); // initialise with this member BlockPair blockPair = new BlockPair(aMapping.getrAtomContainer(), aMapping.getpAtomContainer()); // add the mappings for (int i = 0; i < mappingComponent.size(); i++) { DefinedMapping definedMapping = mappingComponent.get(i); IMapping mapping = reaction.getMapping(definedMapping.getIndex()); blockPair.addMapping(mapping, definedMapping.getRAtom(), definedMapping.getPAtom()); } return blockPair; }).forEach((blockPair) -> { blockPairs.add(blockPair); }); return blockPairs; }
private List<IMapping> cloneMappings(IReaction reaction, Map<IAtom, IAtom> atomAtomMap) { // clone the mappings int numberOfMappings = reaction.getMappingCount(); List<IMapping> map = new ArrayList<IMapping>(); for (int mappingIndex = 0; mappingIndex < numberOfMappings; mappingIndex++) { IMapping mapping = reaction.getMapping(mappingIndex); IChemObject keyChemObj0 = mapping.getChemObject(0); IChemObject keyChemObj1 = mapping.getChemObject(1); IChemObject co0 = (IChemObject) atomAtomMap.get(keyChemObj0); IChemObject co1 = (IChemObject) atomAtomMap.get(keyChemObj1); map.add(new Mapping(co0, co1)); } return map; }
/** * * @param reaction * @return */ public List<BlockPair> createBlockPairs(IReaction reaction) { List<BlockPair> blockPairs = new ArrayList<>(); List<DefinedMapping> definedMappings = createDefinedMappings(reaction); List<List<DefinedMapping>> mappingComponents = findMappedConnectedComponents(reaction, definedMappings); mappingComponents.stream().map((mappingComponent) -> { // all components have at least one member DefinedMapping aMapping = mappingComponent.get(0); // initialise with this member BlockPair blockPair = new BlockPair(aMapping.getrAtomContainer(), aMapping.getpAtomContainer()); // add the mappings for (int i = 0; i < mappingComponent.size(); i++) { DefinedMapping definedMapping = mappingComponent.get(i); IMapping mapping = reaction.getMapping(definedMapping.getIndex()); blockPair.addMapping(mapping, definedMapping.getRAtom(), definedMapping.getPAtom()); } return blockPair; }).forEach((blockPair) -> { blockPairs.add(blockPair); }); return blockPairs; }
/** * This test checks of different numbering for the same mapping gives the same result. */ @Test public void testAsadExamples() throws Exception { String filename = "data/mdl/output.rxn"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLRXNReader reader = new MDLRXNReader(ins); IReactionSet reactionSet = (IReactionSet) reader.read(new ReactionSet()); reader.close(); filename = "data/mdl/output_Cleaned.rxn"; logger.info("Testing: " + filename); ins = this.getClass().getClassLoader().getResourceAsStream(filename); reader = new MDLRXNReader(ins); IReactionSet reactionSet2 = (IReactionSet) reader.read(new ReactionSet()); reader.close(); Assert.assertEquals(reactionSet.getReaction(0).getMappingCount(), reactionSet2.getReaction(0).getMappingCount()); for (int i = 0; i < reactionSet.getReaction(0).getMappingCount(); i++) { Assert.assertEquals(getAtomNumber(reactionSet, reactionSet.getReaction(0).getMapping(i).getChemObject(0)), getAtomNumber(reactionSet2, reactionSet2.getReaction(0).getMapping(i).getChemObject(0))); Assert.assertEquals(getAtomNumber(reactionSet, reactionSet.getReaction(0).getMapping(i).getChemObject(1)), getAtomNumber(reactionSet2, reactionSet2.getReaction(0).getMapping(i).getChemObject(1))); } }
@Test public void testGetMapping_int() { IReaction reaction = (IReaction) newChemObject(); IMapping mapping = reaction.getBuilder().newInstance(IMapping.class, reaction.getBuilder().newInstance(IAtom.class, "C"), reaction.getBuilder().newInstance(IAtom.class, "C")); reaction.addMapping(mapping); IMapping gotIt = reaction.getMapping(0); Assert.assertEquals(mapping, gotIt); }