@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; }
@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; }
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());
/** * 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; } } } } } }
/** * 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; }
String ctab = getCTAB(rgroup.getGroup()); ctab = ctab.replaceAll(LSEP + "M END" + LSEP, ""); rgpBlock.append(ctab).append(LSEP); 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));
int rNum=rnumItr.next(); for (RGroup rgrp: hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().get(rNum).getRGroups()) { rgrp.getGroup().setProperty(CDKConstants.TITLE,RGroup.makeLabel(rNum));
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;
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)))
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()))
rgrpClone = (IAtomContainer) (substitute.getGroup().clone()); } catch (CloneNotSupportedException e) { throw new CDKException("clone() failed; could not perform R-group substitution."); if (subsAt != null) { IAtom subsCloneAtom = rgrpClone.getAtom(getAtomPosition(subsAt, substitute.getGroup())); cloneBond.setAtom(subsCloneAtom, whichAtomInBond);
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>(); removeCheck: for(IAtom atom : molecule.atoms()) { if (subst.getGroup().contains(atom)) { remove=true; break removeCheck;
/** * 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; }