RGroupList rgrpList = rgrpQuery.getRGroupDefinitions().get(rgrpNum);
if(rgrpList!=null) {
existingRgroupLists.put(rgrpNum, makeClone(rgrpList));
List<RGroup> cleanList = new ArrayList<RGroup>();
for (int j=0; j<rgrpList.getRGroups().size(); j++){
RGroup subst= rgrpList.getRGroups().get(j);
boolean remove=false;
removeCheck:
for(IAtom atom : molecule.atoms()) {
if (subst.getGroup().contains(atom)) {
remove=true;
break removeCheck;
}
}
if (!remove) {
cleanList.add(subst);
}
}
rgrpList.setRGroups(cleanList);
}
}
hub.getChemModel().getMoleculeSet().addAtomContainer(molecule);
molecule.setProperty(CDKConstants.TITLE,RGroup.makeLabel(rNum));
RGroup rgrp = new RGroup();
rgrp.setGroup(molecule);
rgrpQuery.getRGroupDefinitions().get(rNum).getRGroups().add(rgrp);
//Set default APO atoms (randomly picked) for the new substitute
int apoCount=validRnumChoices.get(rNum);
int apoSet=0;
apoBreak:
for(IAtom atom : molecule.atoms()) {
if (apoSet==apoCount)
break apoBreak;
if (apoSet==0) {
rgrp.setFirstAttachmentPoint(atom);
}
if (apoSet==1) {
rgrp.setSecondAttachmentPoint(atom);
}
apoSet++;
}
}