rgrpQ.setRootStructure(redoRootStructure); rgrpQ.getRootStructure().setProperty(CDKConstants.TITLE,RGroup.ROOT_LABEL); rgrpQ.setRootAttachmentPoints(redoRootAttachmentPoints); for(Iterator<Integer> rNums=redoRgroupLists.keySet().iterator(); rNums.hasNext();){ int rNum= rNums.next(); rgrpQ.getRGroupDefinitions().put(rNum, redoRgroupLists.get(rNum)); for (Iterator<Integer> rnumItr= hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) { for (RGroup rgrp: hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().get(rnumItr.next()).getRGroups()) { if(rgrp.equals(redoRGroup)) { IAtom apo1=redoRGroupApo.get(redoRGroup).get(1); for(Iterator<IAtom> atItr=redoRootAttachmentPoints.keySet().iterator(); atItr.hasNext();) { IAtom rAtom= atItr.next(); Map<Integer,IBond> apoBonds = hub.getRGroupHandler().getrGroupQuery().getRootAttachmentPoints().get(rAtom);
/** * Initializes an empty RGroupQuery. * * @return a new empty RGroupQuery */ private IRGroupQuery newRGroupQuery(IChemObjectBuilder builder) { IRGroupQuery rgrpQuery = new RGroupQuery(DefaultChemObjectBuilder.getInstance()); rgrpQuery.setRootStructure(builder.newInstance(IAtomContainer.class)); rgrpQuery .setRootAttachmentPoints(new HashMap<IAtom, Map<Integer, IBond>>()); rgrpQuery.setRGroupDefinitions(new HashMap<Integer, RGroupList>()); return rgrpQuery; }
Map<Integer,RGroupList> def = rGroupQuery.getRGroupDefinitions(); for(Iterator<Integer> itr= def.keySet().iterator();itr.hasNext();) { int rgrpNum=itr.next(); root.put(0,rGroupQuery.getRootStructure().hashCode()); rgrpHash.put(-1,root );
File outFile = chooser.getSelectedFile(); System.out.println(outFile); List<IAtomContainer> molecules= jcpPanel.get2DHub().getRGroupHandler().getrGroupQuery().getAllConfigurations(); if (molecules.size() > 0) { IAtomContainerSet molSet = molecules.get(0).getBuilder().newInstance(IAtomContainerSet.class); IAtom apoAtom = (IAtom) eventSource; apoLoop: 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>>(); pseudo=apoBond.getAtom(1); Map<Integer, IBond> keepApoBonds = new HashMap<Integer, IBond>(); if (rGroupHandler.getrGroupQuery().getRootAttachmentPoints()!=null && rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo)!=null) { apoBonds= rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo); for (Iterator<Integer> apoItr =apoBonds.keySet().iterator(); apoItr.hasNext();) { int apoNum=apoItr.next(); if (rGroupHandler.getrGroupQuery().getRootAttachmentPoints()==null) { rGroupHandler.getrGroupQuery().setRootAttachmentPoints(new HashMap<IAtom, Map<Integer, IBond>>()); Map<IAtom, Map<Integer, IBond>> rootApo=rGroupHandler.getrGroupQuery().getRootAttachmentPoints(); if (rootApo.get(pseudo)==null) { apoBonds=new HashMap<Integer,IBond>(); apoBonds=rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo);
IAtomContainer rootAtc = rGroupQuery.getRootStructure(); for (Integer rgrpNum : rGroupQuery.getRGroupDefinitions().keySet()) { RGroupList rgList = rGroupQuery.getRGroupDefinitions().get(rgrpNum); int restH = rgList.isRestH() ? 1 : 0; String logLine = "M LOG" + MDLV2000Writer.formatMDLInt(1, 3) + MDLV2000Writer.formatMDLInt(rgrpNum, 4) for (IAtom rgroupAtom : rGroupQuery.getRootAttachmentPoints().keySet()) { Map<Integer, IBond> rApo = rGroupQuery.getRootAttachmentPoints().get(rgroupAtom); if (rApo.size() > 1) { int prevPos = -1; for (Integer rgrpNum : rGroupQuery.getRGroupDefinitions().keySet()) { List<RGroup> rgrpList = rGroupQuery.getRGroupDefinitions().get(rgrpNum).getRGroups(); if (rgrpList != null && rgrpList.size() != 0) { rgpBlock.append("$RGP").append(LSEP);;
for (IAtom movedAtom : newAtc.atoms()) { if (rGroupQuery.getRootStructure().contains(movedAtom)) { rGroupQuery.setRootStructure(newAtc); newAtc.setProperty(CDKConstants.TITLE, RGroup.ROOT_LABEL); hasRoot=true; Map<Integer,RGroupList> def = rGroupQuery.getRGroupDefinitions(); for(Iterator<Integer> itr= def.keySet().iterator();itr.hasNext();) { int rgrpNum=itr.next();
/** * Helper to get an ordered list of R-group numbers for a certain IRGroupQuery. * @param RgroupQuery * @return an ordered list of R-group numbers in rgroupQuery. */ private List<Integer> sortRGroupNumbers () { List<Integer> rNumbers = new ArrayList<Integer>(); if (rGroupQuery!=null) { for (Iterator<Integer> itr = rGroupQuery.getRGroupDefinitions().keySet().iterator(); itr.hasNext(); ) { rNumbers.add(itr.next()); } Collections.sort(rNumbers); } return rNumbers; }
/** * 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; } } } } } }
/** * Verifies if a merge is allowed from the R-Group's point of view. * Merging between the root structure and r-group substitutes is not allowed, * because it does not makes sense (plus the root structure could get lost). * @param hub controller hub that is about to do a merge. */ public boolean isMergeAllowed(IChemModelRelay hub) { //System.out.println("^^^ isMergeAllowed(IChemModelRelay hub)"); if (rGroupQuery!=null) { for (Iterator<IAtom> it = hub.getRenderer().getRenderer2DModel().getMerge().keySet().iterator(); it.hasNext();) { IAtom mergedAtom = it.next(); IAtom mergedPartnerAtom = hub.getRenderer().getRenderer2DModel().getMerge().get(mergedAtom); IAtomContainer container1 = ChemModelManipulator.getRelevantAtomContainer(hub.getChemModel(), mergedAtom); IAtomContainer container2 = ChemModelManipulator.getRelevantAtomContainer(hub.getChemModel(), mergedPartnerAtom); if(container1!=container2) { List<IAtomContainer> substitutes = rGroupQuery.getSubstituents(); if ((container1==rGroupQuery.getRootStructure() && substitutes.contains(container2)) || (container2==rGroupQuery.getRootStructure() && substitutes.contains(container1))) { JOptionPane.showMessageDialog(jcpPanel.getRenderPanel(), GT.get("This operation is not allowed in the R-Group configuration."), GT.get("R-Group alert"), JOptionPane.INFORMATION_MESSAGE); return false; } } } } return true; }
/** * Method to check whether a given bond exists in the root and is attached * to an R-Group. * @param bond */ public boolean isRGroupRootBond(IBond bond) { if (rGroupQuery!=null && rGroupQuery.getRootStructure()!=null && rGroupQuery.getRootStructure().contains(bond)) { for(IAtom atom : bond.atoms()) { if (atom instanceof IPseudoAtom && RGroupQuery.isValidRgroupQueryLabel(((IPseudoAtom)atom).getLabel())) { return true; } } } return false; }
/** * Labels bonds going into root R-groups with appropriate symbol. * @param diagram */ private void labelRootApoBonds (ElementGroup diagram,IAtomContainer ac) { Map<IAtom, Map<Integer, IBond>> rootAttachmentPoints = rGroupQuery.getRootAttachmentPoints(); for (Iterator<IAtom> atomItr=rootAttachmentPoints.keySet().iterator(); atomItr.hasNext();) { Map<Integer,IBond> bonds =rootAttachmentPoints.get(atomItr.next()); for(Iterator<Integer> bondItr=bonds.keySet().iterator(); bondItr.hasNext();) { int bondNum=bondItr.next(); IBond b = bonds.get(bondNum); if (ac.contains(b)) { double xAvg = (b.getAtom(0).getPoint2d().x + b.getAtom(1).getPoint2d().x)/2; double yAvg = (b.getAtom(0).getPoint2d().y + b.getAtom(1).getPoint2d().y)/2; diagram.add(new TextElement(xAvg+0.1, yAvg-0.1,(bondNum==1?APO1_LABEL:APO2_LABEL),APO_LABEL_COLOR)); } } } }
jcpPanel.get2DHub().getRGroupHandler().cleanUpRGroup(jcpPanel.get2DHub().getChemModel().getMoleculeSet()); if(!rGroupQuery.areRootAtomsDefined()) { message = GT.get("The R-group Query is not valid: there are substitutes that have no corresponding atom in the root structure."); problem=true; if(!rGroupQuery.areSubstituentsDefined()) { message = GT.get("The R-group Query is not valid: the root structure has R# definitions for which no substitutes are defined."); problem=true;
this.existingBondDistr=_existingBondDistr; this.existingRgroupLists=_existingRgroupLists; this.redoRootStructure=rgrpHandler.getrGroupQuery().getRootStructure(); this.userSelection=(IAtomContainer)_userSelection; if (_existingRgroupLists!=null) { redoRgroupLists = new HashMap<Integer,RGroupList>(); for (Iterator<Integer> itr=rgrpHandler.getrGroupQuery().getRGroupDefinitions().keySet().iterator(); itr.hasNext();) { int rNum=itr.next(); redoRgroupLists.put(rNum, rgrpHandler.getrGroupQuery().getRGroupDefinitions().get(rNum)); for (Iterator<Integer> rnumItr= hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) { for (RGroup rgrp: hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().get(rnumItr.next()).getRGroups()) { if(rgrp.equals(undoRGroup)) { redoRGroupApo= new HashMap <RGroup,Map<Integer,IAtom>>();
/** * 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; }
/** * Method to detect if removing atoms/bonds has unwanted results for * the R-group. * * @param atc * @param hub * @return */ public boolean checkRGroupOkayForDelete(IAtomContainer atc,IChemModelRelay hub ) { //Check if the root would still remain there (partly) after a delete.. if(rGroupQuery!=null) { boolean rootRemains=false; root: for(IAtom a : rGroupQuery.getRootStructure().atoms()) { if (!atc.contains(a)){ rootRemains=true; break root; } } if (!rootRemains) { int answer = JOptionPane.showConfirmDialog(jcpPanel.getRenderPanel(), GT.get("This operation would irreversibly remove the R-Group query. Continue?"), GT.get("R-Group alert"), JOptionPane.YES_NO_OPTION); if(answer == JOptionPane.NO_OPTION) return false; } } return true; }
this.redoRootAttachmentPoints=rgrpHandler.getrGroupQuery().getRootAttachmentPoints(); for (Iterator<IAtom> atItr = existingAtomDistr.keySet().iterator(); atItr.hasNext();) { IAtom atom = atItr.next(); rgrpQ.setRootStructure(null); rgrpQ.setRootAttachmentPoints(null); for (IAtomContainer atc: hub.getIChemModel().getMoleculeSet().atomContainers()) { atc.removeProperty(CDKConstants.TITLE); rgrpQ.setRootStructure(existingRoot); rgrpQ.setRootAttachmentPoints(existingRootAttachmentPoints); for(Iterator<Integer> rNums=existingRgroupLists.keySet().iterator(); rNums.hasNext();){ int rNum= rNums.next(); rgrpQ.getRGroupDefinitions().put(rNum, existingRgroupLists.get(rNum)); for (Iterator<Integer> rnumItr= hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) { for (RGroup rgrp: hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().get(rnumItr.next()).getRGroups()) { if(rgrp.equals(undoRGroup)) { IAtom apo1=existingRGroupApo.get(undoRGroup).get(1); IAtom rAtom= atItr.next(); Map<Integer,IBond> undoApo = existingRootAttachmentPoints.get(rAtom); Map<Integer,IBond> apoBonds = rgrpQ.getRootAttachmentPoints().get(rAtom); rgrpQ.getRootStructure().setProperty(CDKConstants.TITLE, RGroup.ROOT_LABEL); for (Iterator<Integer> rnumItr= hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) { int rNum=rnumItr.next(); for (RGroup rgrp: hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().get(rNum).getRGroups()) {
/** * 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; }
List<Integer> rgrpToRemove=new ArrayList<Integer>(); if (rGroupQuery!=null){ Map<Integer,RGroupList> def = rGroupQuery.getRGroupDefinitions(); for(Iterator<Integer> itr= def.keySet().iterator();itr.hasNext();) { for (RGroup rgrp :rGroupQuery.getRGroupDefinitions().get(rgrpNum).getRGroups()) { atomCount+=rgrp.getGroup().getAtomCount(); rGroupQuery.getRGroupDefinitions().remove(rgrpNum);
if (ac==rGroupQuery.getRootStructure()) { if (rGroupQuery.getRGroupDefinitions().keySet()!=null) { apo: 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;
private void constructPanel() { rNumbers= new ArrayList<Integer>(); for (Iterator<Integer> rnumItr=hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) { rNumbers.add(rnumItr.next()); } Collections.sort(rNumbers); for(Integer r : rNumbers) { JPanel rgrpPanel = this.addTab("R"+r); JTextField occurrenceField = new JTextField(20); occurrenceField.setName("occurrence"); addField(GT.get("Occurrence"), occurrenceField, rgrpPanel,DEF_INSET); String[] trueFalseStrings = { GT.get("True"), GT.get("False")}; JComboBox<?> restHBox= new JComboBox<Object>(trueFalseStrings); restHBox.setName("restH"); addField(GT.get("Rest H"), restHBox, rgrpPanel,DEF_INSET); List<String> otherRnums = new ArrayList<String>(); otherRnums.add(GT.get("None")); for (Iterator<Integer> rnumItr=hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) { int r_=rnumItr.next(); if (r_!= r) { otherRnums.add("R"+r_); } } String[] ifThenStrings=(String[])(otherRnums.toArray(new String[otherRnums.size()])); JComboBox<?> ifThenBox = new JComboBox<Object>(ifThenStrings); ifThenBox.setName("ifThen"); addField(GT.get("If R" + r + " then "), ifThenBox, rgrpPanel,DEF_INSET); panels.add(rgrpPanel); } }