if (rgp!=null) { Map<Integer,Integer> hash = new HashMap<Integer,Integer>(); hash.put(0, rgp.getGroup()==null?null:rgp.getGroup().hashCode()); hash.put(1, rgp.getFirstAttachmentPoint()==null?null:rgp.getFirstAttachmentPoint().hashCode()); hash.put(2, rgp.getSecondAttachmentPoint()==null?null:rgp.getSecondAttachmentPoint().hashCode()); rgrpHash.put(rgp.hashCode(),hash);
/** * See restores what was saved by makeHash(). */ public void restoreFromHash(Map<Integer,Map<Integer,Integer>> mash, IAtomContainerSet mset) { if(rGroupQuery!=null) { int rootHash = mash.get(-1).get(0); rGroupQuery.setRootStructure(findContainer(rootHash,mset)); Map<Integer,RGroupList> def = rGroupQuery.getRGroupDefinitions(); for (Iterator<Integer>rgpHashItr=mash.keySet().iterator(); rgpHashItr.hasNext();) { int rgpHash = rgpHashItr.next(); restore: for(Iterator<Integer> itr= def.keySet().iterator();itr.hasNext();) { int rgrpNum=itr.next(); List<RGroup> rgpList = def.get(rgrpNum).getRGroups(); for(RGroup rgp : rgpList) { if (rgp!=null && rgp.hashCode()==rgpHash) { rgp.setGroup(findContainer(mash.get(rgpHash).get(0),mset)); if (rgp.getGroup()!=null) { rgp.setFirstAttachmentPoint(findAtom(mash.get(rgpHash).get(1),rgp.getGroup())); rgp.setSecondAttachmentPoint(findAtom(mash.get(rgpHash).get(2),rgp.getGroup())); } break restore; } } } } } }
redoRGroupApo= new HashMap <RGroup,Map<Integer,IAtom>>(); HashMap<Integer,IAtom> map = new HashMap<Integer,IAtom>(); map.put(1, rgrp.getFirstAttachmentPoint()); map.put(2, rgrp.getSecondAttachmentPoint()); redoRGroupApo.put(rgrp,map);
for (Iterator<Integer> rnumItr=rGroupHandler.getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) { for (RGroup rgrp: rGroupHandler.getrGroupQuery().getRGroupDefinitions().get(rnumItr.next()).getRGroups()) { if(rgrp.getGroup().contains(apoAtom)) { existingRGroupApo= new HashMap <RGroup,Map<Integer,IAtom>>(); HashMap<Integer,IAtom> map = new HashMap<Integer,IAtom>(); map.put(1, rgrp.getFirstAttachmentPoint()); map.put(2, rgrp.getSecondAttachmentPoint()); existingRGroupApo.put(rgrp,map); rgrp.setFirstAttachmentPoint(apoAtom); rgrp.setSecondAttachmentPoint(apoAtom); removeCheck: for(IAtom atom : molecule.atoms()) { if (subst.getGroup().contains(atom)) { remove=true; break removeCheck; molecule.setProperty(CDKConstants.TITLE,RGroup.makeLabel(rNum)); RGroup rgrp = new RGroup(); rgrp.setGroup(molecule); rgrpQuery.getRGroupDefinitions().get(rNum).getRGroups().add(rgrp); break apoBreak; if (apoSet==0) { rgrp.setFirstAttachmentPoint(atom);
for (int i = 0; i < rgpList.size(); i++) { if(rgpList.get(i).getGroup().contains(movedAtom)|| (rgpList.get(i).getFirstAttachmentPoint()!=null && rgpList.get(i).getFirstAttachmentPoint().equals(movedAtom))) rgpList.get(i).setGroup(newAtc); newAtc.setProperty(CDKConstants.TITLE, RGroup.makeLabel(rgrpNum)); break atoms;
IAtom apo1=existingRGroupApo.get(undoRGroup).get(1); IAtom apo2=existingRGroupApo.get(undoRGroup).get(2); rgrp.setFirstAttachmentPoint(apo1); rgrp.setSecondAttachmentPoint(apo2); int rNum=rnumItr.next(); for (RGroup rgrp: hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().get(rNum).getRGroups()) { rgrp.getGroup().setProperty(CDKConstants.TITLE,RGroup.makeLabel(rNum));
sb = new StringBuilder(RGroup.makeLabel(rgroupNum) + "\n\n\n"); line = input.readLine(); while (line != null && !line.startsWith("$END CTAB")) { reader = new MDLV2000Reader(new StringReader(groupStr), ISimpleChemObjectReader.Mode.STRICT); IAtomContainer group = reader.read(defaultChemObjectBuilder.newInstance(IAtomContainer.class)); RGroup rGroup = new RGroup(); rGroup.setGroup(group); switch (apo) { case 1: rGroup.setFirstAttachmentPoint(at); break; case 2: rGroup.setSecondAttachmentPoint(at); break; case 3: { rGroup.setFirstAttachmentPoint(at); rGroup.setSecondAttachmentPoint(at);
@Override public List<IAtomContainer> getSubstituents() { List<IAtomContainer> substitutes = new ArrayList<IAtomContainer>(); for (Integer r : rGroupDefinitions.keySet()) { for (RGroup rgrp : rGroupDefinitions.get(r).getRGroups()) { IAtomContainer subst = rgrp.getGroup(); if (subst != null) substitutes.add(subst); } } return substitutes; }
IAtom apo1=redoRGroupApo.get(redoRGroup).get(1); IAtom apo2=redoRGroupApo.get(redoRGroup).get(2); rgrp.setFirstAttachmentPoint(apo1); rgrp.setSecondAttachmentPoint(apo2);
Assert.assertEquals(rGroups.get(0).getFirstAttachmentPoint(), null); Assert.assertEquals(rGroups.get(0).getSecondAttachmentPoint(), null); Assert.assertEquals(rGroups.get(1).getFirstAttachmentPoint(), null); Assert.assertEquals(rGroups.get(1).getSecondAttachmentPoint(), null);
@Override public int getAtomContainerCount() { int retVal = 0; if (this.rootStructure != null) retVal++; for (Integer r : rGroupDefinitions.keySet()) { for (RGroup rgrp : rGroupDefinitions.get(r).getRGroups()) { if (rgrp.getGroup() != null) { retVal++; } } } return retVal; }
for(Iterator<Integer> itr =rGroupQuery.getRGroupDefinitions().keySet().iterator();itr.hasNext();) { for (RGroup rgrp :rGroupQuery.getRGroupDefinitions().get(itr.next()).getRGroups()) { if(rgrp.getGroup()==ac) { acDetachedFromRGroup=false; if(ac.contains(rgrp.getFirstAttachmentPoint())) labelApoAtoms(rgrp.getFirstAttachmentPoint(),diagram,APO1_LABEL,ac,jcpModel); if (ac.contains(rgrp.getSecondAttachmentPoint())) labelApoAtoms(rgrp.getSecondAttachmentPoint(),diagram,APO2_LABEL,ac,jcpModel); break apo;
Assert.assertEquals(rGroups.get(0).getFirstAttachmentPoint().getSymbol(), "N"); Assert.assertEquals(rGroups.get(1).getFirstAttachmentPoint().getSymbol(), "O"); Assert.assertEquals(rGroups.get(2).getFirstAttachmentPoint().getSymbol(), "S"); Assert.assertNull(rGroups.get(0).getSecondAttachmentPoint()); Assert.assertNull(rGroups.get(1).getSecondAttachmentPoint()); Assert.assertNull(rGroups.get(2).getSecondAttachmentPoint());
String ctab = getCTAB(rgroup.getGroup()); ctab = ctab.replaceAll(LSEP + "M END" + LSEP, ""); rgpBlock.append(ctab).append(LSEP); IAtom firstAttachmentPoint = rgroup.getFirstAttachmentPoint(); IAtom secondAttachmentPoint = rgroup.getSecondAttachmentPoint(); int apoCount = 0; if (firstAttachmentPoint != null) { StringBuffer apoLine = new StringBuffer(); for (int atIdx = 0; atIdx < rgroup.getGroup().getAtomCount(); atIdx++) { if (rgroup.getGroup().getAtom(atIdx).equals(firstAttachmentPoint)) { apoLine.append(MDLV2000Writer.formatMDLInt((atIdx + 1), 4)); apoCount++; for (int atIdx = 0; atIdx < rgroup.getGroup().getAtomCount(); atIdx++) { if (rgroup.getGroup().getAtom(atIdx).equals(secondAttachmentPoint)) { apoCount++; apoLine.append(MDLV2000Writer.formatMDLInt((atIdx + 1), 4));
Assert.assertEquals(rList.getRGroups().size(), 2); List<RGroup> rGroups = rList.getRGroups(); Assert.assertEquals(rGroups.get(0).getSecondAttachmentPoint().getSymbol(), "O"); Assert.assertEquals(rGroups.get(1).getSecondAttachmentPoint().getSymbol(), "O"); Assert.assertFalse(rList.isRestH()); Assert.assertEquals(rGroups.get(0).getFirstAttachmentPoint().getSymbol(), "Pt"); Assert.assertEquals(rGroups.get(0).getSecondAttachmentPoint(), null);
/** * Method to check whether a given atom is part of one of the substitutes. * @param atom */ public boolean isAtomPartOfSubstitute(IAtom atom) { if (rGroupQuery!=null && rGroupQuery.getRGroupDefinitions()!=null) { for (Iterator<Integer> itr = rGroupQuery.getRGroupDefinitions().keySet().iterator(); itr.hasNext(); ) { RGroupList rgpList =rGroupQuery.getRGroupDefinitions().get(itr.next()); if(rgpList!=null && rgpList.getRGroups()!=null) { for (RGroup rgrp: rgpList.getRGroups() ) { if(rgrp.getGroup().contains(atom)) { return true; } } } } } return false; }
rgrpClone = (IAtomContainer) (substitute.getGroup().clone()); } catch (CloneNotSupportedException e) { throw new CDKException("clone() failed; could not perform R-group substitution."); IAtom subsAt = null; if (apo == 0) subsAt = substitute.getFirstAttachmentPoint(); else subsAt = substitute.getSecondAttachmentPoint(); if (subsAt != null) { IAtom subsCloneAtom = rgrpClone.getAtom(getAtomPosition(subsAt, substitute.getGroup())); cloneBond.setAtom(subsCloneAtom, whichAtomInBond); && substitute.getFirstAttachmentPoint() != null && substitute.getFirstAttachmentPoint().getPoint2d() != null) { Point2d pointR = rAtom.getPoint2d(); Point2d pointC = substitute.getFirstAttachmentPoint().getPoint2d(); double xDiff = pointC.x - pointR.x; double yDiff = pointC.y - pointR.y;
for (RGroup rgrp : rgrpList.getRGroups()) { double rgrpXleft=(findBoundary(rgrp.getGroup(),true,true,Double.POSITIVE_INFINITY)); double rgrpYtop=(findBoundary(rgrp.getGroup(),false,false,Double.NEGATIVE_INFINITY)); double shiftX= (listXRight - rgrpXleft); double shiftY= (yBottom - rgrpYtop); for (IAtom atom : rgrp.getGroup().atoms()) { atom.setPoint2d(new Point2d (atom.getPoint2d().x+shiftX, atom.getPoint2d().y+shiftY )); minListYBottom=(findBoundary(rgrp.getGroup(),false,true,minListYBottom)); double rgrpXRight=(findBoundary(rgrp.getGroup(),true,false,Double.NEGATIVE_INFINITY)); listXRight=rgrpXRight+MARGIN;
/** * Creates a {@link org.openscience.cdk.interfaces.IAtomContainerSet} from a * provided {@link org.openscience.cdk.isomorphism.matchers.IRGroupQuery). * The root structure becomes the atom container as position zero, the * substitutes follow on position 1..n, ordered by R-group number. * * @param chemModel * @param RgroupQuery * @throws CDKException */ public IAtomContainerSet getMoleculeSet (IChemModel chemModel) throws CDKException { if (rGroupQuery==null || rGroupQuery.getRootStructure() == null || rGroupQuery.getRootStructure().getAtomCount()==0) throw new CDKException( "The R-group is empty"); IAtomContainerSet moleculeSet = chemModel.getBuilder().newInstance(IAtomContainerSet.class); moleculeSet.addAtomContainer(rGroupQuery.getRootStructure()); chemModel.setMoleculeSet(moleculeSet); for (int rgrpNum : sortRGroupNumbers()) { RGroupList rgrpList = rGroupQuery.getRGroupDefinitions().get(rgrpNum); for (RGroup rgrp : rgrpList.getRGroups()) { chemModel.getMoleculeSet().addAtomContainer(rgrp.getGroup()); } } return moleculeSet; }