public void applyChanges() { String label=labelField.getText(); if (label!=null && label.startsWith("R")&&label.length()>1 && !RGroupQuery.isValidRgroupQueryLabel(label) ) { JOptionPane.showMessageDialog(null, GT.get("This is not a valid R-group label.\nPlease label in range R1 .. R32")); } else { IPseudoAtom atom = (IPseudoAtom)source; atom.setLabel(labelField.getText()); } } }
/** * 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; }
@Override public List<IAtomContainer> getAllConfigurations() throws CDKException { if (!areSubstituentsDefined()) { throw new CDKException("Can not configure molecules: missing R# group definitions."); int r = rGroupNumItr.next(); rGroupNumbers.add(r); List<Integer> validOcc = rGroupDefinitions.get(r).matchOccurence(getRgroupQueryAtoms(r).size()); if (validOcc.size() == 0) { throw new CDKException("Occurrence '" + rGroupDefinitions.get(r).getOccurrence() findConfigurationsRecursively(rGroupNumbers, occurrences, occurIndexes, distributions, substitutes, 0, result);
@Override public boolean areSubstituentsDefined() { List<IAtom> allRgroupAtoms = getAllRgroupQueryAtoms(); if (allRgroupAtoms == null) return false; for (IAtom rgp : allRgroupAtoms) { if (RGroupQuery.isValidRgroupQueryLabel(((IPseudoAtom) rgp).getLabel())) { int groupNum = Integer.valueOf(((IPseudoAtom) rgp).getLabel().substring(1)); if (rGroupDefinitions == null || rGroupDefinitions.get(groupNum) == null || rGroupDefinitions.get(groupNum).getRGroups() == null || rGroupDefinitions.get(groupNum).getRGroups().size() == 0) { return false; } } } return true; }
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); RGroupQueryReader reader = new RGroupQueryReader(ins); RGroupQuery rGroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); reader.close(); Assert.assertNotNull(rGroupQuery); Assert.assertEquals(rGroupQuery.getRGroupDefinitions().size(), 1); Assert.assertEquals(rGroupQuery.getRootStructure().getAtomCount(), 10); Assert.assertEquals(rGroupQuery.getRootAttachmentPoints().size(), 2); Assert.assertEquals(rGroupQuery.getAllConfigurations().size(), 8); for (IAtom at : rGroupQuery.getRgroupQueryAtoms(1)) { if (at instanceof PseudoAtom) { Assert.assertEquals(((PseudoAtom) at).getLabel(), "R1"); Map<Integer, IBond> apoBonds = rGroupQuery.getRootAttachmentPoints().get(at); Assert.assertEquals(apoBonds.size(), 2); List<IAtom> allrGroupQueryAtoms = rGroupQuery.getAllRgroupQueryAtoms(); Assert.assertEquals(allrGroupQueryAtoms.size(), 2);
if (!checkIfThenConditionsMet(rGroupNumbers, distributions)) return; IAtomContainer root = this.getRootStructure(); IAtomContainer rootClone = null; try { IAtom rAtom = this.getRgroupQueryAtoms(rNum).get(pos); if (substitute != null) { Map<Integer, IBond> rAttachmentPoints = this.getRootAttachmentPoints().get(rAtom); if (rAttachmentPoints != null) { IBond cloneBond = rootClone.getBond(getBondPosition(bond, root)); if (subsAt != null) { IAtom subsCloneAtom = rgrpClone.getAtom(getAtomPosition(subsAt, substitute.getGroup())); cloneBond.setAtom(subsCloneAtom, whichAtomInBond); IAtom discarded = rootClone.getAtom(getAtomPosition(rAtom, root)); for (IBond r0Bond : rootClone.bonds()) { if (r0Bond.contains(discarded)) { for (IAtom atInBond : r0Bond.atoms()) { atInBond.setProperty(CDKConstants.REST_H, this.getRGroupDefinitions().get(rNum) .isRestH()); boolean removeBond = false; if (cloneBond.getBegin() instanceof IPseudoAtom && isValidRgroupQueryLabel(((IPseudoAtom) cloneBond.getBegin()).getLabel())) removeBond = true;
/** * Test parsing of RGFile rgfile.6.mol. * This RGFile is incomplete, RGP lines are missing. We still want to * accept it (Symyx/ChemAxon software accepts it too). */ @Test(expected = CDKException.class) public void testRgroupQueryFile6() throws Exception { String filename = "data/mdl/rgfile.6.mol"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); RGroupQueryReader reader = new RGroupQueryReader(ins); RGroupQuery rGroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); reader.close(); Assert.assertNotNull(rGroupQuery); Assert.assertEquals(rGroupQuery.getRGroupDefinitions().size(), 3); Assert.assertEquals(rGroupQuery.getRootStructure().getAtomCount(), 14); // This file has missing $RGP blocks. You could argue that this is // thus not a legal query (ie missing query specifications) Assert.assertFalse(rGroupQuery.areSubstituentsDefined()); //Getting for all configurations won't happen, because not all groups were set rGroupQuery.getAllConfigurations(); // Will raise exception }
IChemObjectBuilder defaultChemObjectBuilder = rGroupQuery.getBuilder(); String line = ""; int lineCount = 0; rGroupQuery.setRootStructure(root); rGroupQuery.setRootAttachmentPoints(attachmentPoints); logger.info("Attachm.points defined for " + attachmentPoints.size() + " R# atoms"); if (atom instanceof IPseudoAtom) { IPseudoAtom rGroup = (IPseudoAtom) atom; if (RGroupQuery.isValidRgroupQueryLabel(rGroup.getLabel())) { int rgroupNum = Integer.valueOf(rGroup.getLabel().substring(1)); RGroupList rgroupList = new RGroupList(rgroupNum); rGroupQuery.setRGroupDefinitions(rGroupDefinitions); logger.info("Number of lines was " + lineCount); return rGroupQuery;
/** * Test parsing of RGFile rgfile.5.mol. * This exotic R-group query files has many R# groups and subsitutes, * to test mainly for getting all valid configurations. */ @Test @Category(SlowTest.class) public void testRgroupQueryFile5() throws Exception { String filename = "data/mdl/rgfile.5.mol"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); RGroupQueryReader reader = new RGroupQueryReader(ins); RGroupQuery rGroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); reader.close(); Assert.assertNotNull(rGroupQuery); Assert.assertEquals(rGroupQuery.getRGroupDefinitions().size(), 4); //Test combinatorial explosion: R5 has many different configurations Assert.assertEquals(rGroupQuery.getAllConfigurations().size(), 17820); }
/** * Returns all R# type atoms (pseudo atoms) found in the root structure. * @return list of (pseudo) R# atoms */ public List<IAtom> getAllRgroupQueryAtoms() { return getRgroupQueryAtoms(null); }
@Override public boolean areRootAtomsDefined() { for (Integer rgpNum : rGroupDefinitions.keySet()) { boolean represented = false; rootLoop: for (IAtom rootAtom : this.getRootStructure().atoms()) { if (rootAtom instanceof IPseudoAtom && rootAtom.getSymbol().startsWith("R")) { IPseudoAtom pseudo = (IPseudoAtom) rootAtom; if (pseudo.getLabel().length() > 1) { int rootAtomRgrpNumber = Integer.valueOf(pseudo.getLabel().substring(1)); if (rootAtomRgrpNumber == rgpNum) { represented = true; break rootLoop; } } } } if (!represented) { return false; } } return true; }
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); RGroupQueryReader reader = new RGroupQueryReader(ins); RGroupQuery rGroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); reader.close(); Assert.assertNotNull(rGroupQuery); Assert.assertEquals(rGroupQuery.getRGroupDefinitions().size(), 1); Assert.assertEquals(rGroupQuery.getRootStructure().getAtomCount(), 6); List<IAtom> allrGroupQueryAtoms = rGroupQuery.getAllRgroupQueryAtoms(); Assert.assertEquals(allrGroupQueryAtoms.size(), 1); RGroupList rList = rGroupQuery.getRGroupDefinitions().get(1); Assert.assertEquals(rList.getRGroups().size(), 2); Assert.assertEquals(rList.getRequiredRGroupNumber(), 0); Assert.assertFalse(rList.isRestH()); Assert.assertEquals(rGroupQuery.getRootAttachmentPoints().size(), 0); Assert.assertTrue(rGroupQuery.areSubstituentsDefined()); Assert.assertEquals(rGroupQuery.getAllConfigurations().size(), 2);
/** * Test parsing of RGFile rgfile.7.mol. * This RGFile has APO lines with value 3: both attachment points.<P> * * Also, R32 appears twice, but with different numbers of attachment. * The parser should not trip over this, and make nice configurations. */ @Test public void testRgroupQueryFile7() throws Exception { String filename = "data/mdl/rgfile.7.mol"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); RGroupQueryReader reader = new RGroupQueryReader(ins); RGroupQuery rGroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); reader.close(); Assert.assertNotNull(rGroupQuery); Assert.assertEquals(rGroupQuery.getRGroupDefinitions().size(), 1); Assert.assertEquals(rGroupQuery.getRootStructure().getAtomCount(), 9); Assert.assertEquals(rGroupQuery.getAllConfigurations().size(), 20); }
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); RGroupQueryReader reader = new RGroupQueryReader(ins); RGroupQuery rGroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); reader.close(); Assert.assertNotNull(rGroupQuery); Assert.assertEquals(rGroupQuery.getRGroupDefinitions().size(), 1); Assert.assertEquals(rGroupQuery.getRootStructure().getAtomCount(), 7); for (IAtom at : rGroupQuery.getAllRgroupQueryAtoms()) { if (at instanceof PseudoAtom) { Assert.assertEquals(((PseudoAtom) at).getLabel(), "R1"); Map<IAtom, Map<Integer, IBond>> rootApo = rGroupQuery.getRootAttachmentPoints(); Map<Integer, IBond> apoBonds = rootApo.get(at); Assert.assertEquals(apoBonds.size(), 1); for (IBond bond : rGroupQuery.getRootStructure().bonds()) { if (bond.contains(at)) { Assert.assertEquals(bond, apoBonds.get(1)); Iterator<Integer> itr = rGroupQuery.getRGroupDefinitions().keySet().iterator(); int val_1 = itr.next(); Assert.assertEquals(val_1, 1); RGroupList rList = rGroupQuery.getRGroupDefinitions().get(val_1); Assert.assertEquals(rList.getOccurrence(), "0,1-3"); List<IAtomContainer> configurations = rGroupQuery.getAllConfigurations(); Assert.assertEquals(configurations.size(), 4);
/** * 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; }
private String recreate(String file) throws CDKException { StringWriter sw = new StringWriter(); RGroupQueryWriter rgw = new RGroupQueryWriter(sw); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(file); RGroupQueryReader reader = new RGroupQueryReader(ins); RGroupQuery rGroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); rgw.write(rGroupQuery); String out = sw.toString(); return out; }
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); RGroupQueryReader reader = new RGroupQueryReader(ins); RGroupQuery rGroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); reader.close(); Assert.assertNotNull(rGroupQuery); Assert.assertEquals(rGroupQuery.getRGroupDefinitions().size(), 3); Assert.assertEquals(rGroupQuery.getRootStructure().getAtomCount(), 14); Assert.assertEquals(rGroupQuery.getRootAttachmentPoints().size(), 4); List<IAtom> rGroupQueryAtoms = rGroupQuery.getAllRgroupQueryAtoms(); Assert.assertEquals(rGroupQueryAtoms.size(), 4); rGroupQueryAtoms = rGroupQuery.getRgroupQueryAtoms(1); Assert.assertEquals(rGroupQueryAtoms.size(), 1); for (IAtom at : rGroupQuery.getAllRgroupQueryAtoms()) { if (at instanceof PseudoAtom) { Assert.assertTrue(RGroupQuery.isValidRgroupQueryLabel(((PseudoAtom) at).getLabel())); int rgroupNum = new Integer((((PseudoAtom) at).getLabel()).substring(1)); Assert.assertTrue(rgroupNum == 1 || rgroupNum == 2 || rgroupNum == 11); Map<IAtom, Map<Integer, IBond>> rootApo = rGroupQuery.getRootAttachmentPoints(); Map<Integer, IBond> apoBonds = rootApo.get(at); Assert.assertEquals(apoBonds.size(), 2); RGroupList rList = rGroupQuery.getRGroupDefinitions().get(1); Assert.assertEquals(rList.getRGroups().size(), 2); List<RGroup> rGroups = rList.getRGroups();
if (atom instanceof IPseudoAtom) { IPseudoAtom pseudo = (IPseudoAtom)atom; if (pseudo.getLabel()!=null && RGroupQuery.isValidRgroupQueryLabel(pseudo.getLabel())) { chooseRootAttachmentBonds(pseudo,molecule,apoBonds); if (atom instanceof IPseudoAtom) { IPseudoAtom pseudo = (IPseudoAtom)atom; if (pseudo.getLabel()!=null && RGroupQuery.isValidRgroupQueryLabel(pseudo.getLabel())) { int bondCnt=0; int rNum=new Integer(pseudo.getLabel().substring(1));
protected static IChemObject[] acceptableChemObjects() { return new IChemObject[]{new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction(), new RGroupQuery(DefaultChemObjectBuilder.getInstance())}; }
if (label == null) return; if(label.startsWith("R") && label.length()>1 && !RGroupQuery.isValidRgroupQueryLabel(label)) JOptionPane.showMessageDialog(null, GT.get("This is not a valid R-group label.\nPlease label in range R1 .. R32")); else