📄 generatefragments.java
字号:
/** * add the atoms on the shortest path to the murcko fragment * Care about ring atoms in the path and sidechainHetatoms * @param addAtomContainer path * @param targetMolecule murcko fragment storage * @param mainMolecule original molecule * @return IMolecule murcko fragment */ private IMolecule addPathFragments(IAtomContainer addAtomContainer,IMolecule targetMolecule, IMolecule mainMolecule){ IAtomContainer ringAtomContainer=null; List atoms=null; //1. check if linker atom is member of a ring system //2. check if heteroatoms bonded to a non ring linker atom should be included //3. check if exocyclic double or triple bonded atoms to linker schould be included for (int i=0;i<addAtomContainer.getAtomCount();i++){ if (addAtomContainer.getAtom(i).getFlag(CDKConstants.ISINRING)&& !targetMolecule.contains(addAtomContainer.getAtom(i))){ //Find all Ring atoms and add them for (int j = 0; j < this.ringFragments.size(); j++) { ringAtomContainer = addAtomContainer.getBuilder().newAtomContainer(); IRingSet ringSet = (IRingSet)this.ringFragments.get(j); for (int k=0; k<ringSet.getAtomContainerCount(); k++) { ringAtomContainer.add(ringSet.getAtomContainer(k)); } if (ringAtomContainer.contains(addAtomContainer.getAtom(i))){ targetMolecule=addFragments(ringAtomContainer, targetMolecule,mainMolecule); break; } } }else if((this.sidechainHetatoms || this.exocyclicDoubleBonds) && !targetMolecule.contains(addAtomContainer.getAtom(i))){ atoms=mainMolecule.getConnectedAtomsList(addAtomContainer.getAtom(i)); targetMolecule.addAtom(addAtomContainer.getAtom(i)); for (int j = 0; j < atoms.size(); j++) { IAtom atom = (IAtom)atoms.get(j); //logger.debug("HETATOM:"+atoms[j].getSymbol()); if (this.sidechainHetatoms && !addAtomContainer.getAtom(i).getFlag(CDKConstants.ISINRING) && !(atom.getSymbol()).equals("C") && !(atom.getSymbol()).equals("H") && !targetMolecule.contains(atom)){ //logger.debug("HETATOM TRUE"); targetMolecule.addAtom(atom); } if (this.exocyclicDoubleBonds && mainMolecule.getBond(atom,addAtomContainer.getAtom(i)).getOrder()>1 && !targetMolecule.contains(atom)){ //logger.debug("EXOCYCLIC DB TRUE"); targetMolecule.addAtom(atom); } } }else{ if (!targetMolecule.contains(addAtomContainer.getAtom(i))){ targetMolecule.addAtom(addAtomContainer.getAtom(i)); } } } return targetMolecule; } /** * add bonds to the murcko fragments * @param targetMolecule murcko fragment storage * @param mainMolecule original molecule * @return IMolecule murcko fragment */ private IMolecule addFragmentBonds(IMolecule targetMolecule, IMolecule mainMolecule){ int firstAtomNumber=0; int secondAtomNumber=0; for (int i=0;i<targetMolecule.getAtomCount()-1;i++){ for (int j = i+1; j < targetMolecule.getAtomCount(); j++) { if (mainMolecule.getBond(targetMolecule.getAtom(i),targetMolecule.getAtom(j)) !=null){ firstAtomNumber=targetMolecule.getAtomNumber(targetMolecule.getAtom(i)); secondAtomNumber=targetMolecule.getAtomNumber(targetMolecule.getAtom(j)); targetMolecule.addBond(firstAtomNumber,secondAtomNumber,mainMolecule.getBond(targetMolecule.getAtom(i),targetMolecule.getAtom(j)).getOrder()); if (mainMolecule.getBond(targetMolecule.getAtom(i),targetMolecule.getAtom(j)).getFlag(CDKConstants.ISAROMATIC) == true){ targetMolecule.getBond(targetMolecule.getAtom(firstAtomNumber),targetMolecule.getAtom(secondAtomNumber)).setFlag(CDKConstants.ISAROMATIC, true); } } } } return targetMolecule; } private IMolecule addFragments(IRingSet ringSet, IMolecule targetMolecule, IMolecule mainMolecule){ for (int i=0;i<ringSet.getAtomContainerCount();i++) { addFragments(ringSet.getAtomContainer(i), targetMolecule, mainMolecule); } return targetMolecule; } /** * add the rings to the murcko fragment * @param addAtomContainer IAtomContainer with the ring atoms * @param targetMolecule murcko fragment * @return IMolecule murcko fragment */ private IMolecule addFragments(IAtomContainer addAtomContainer, IMolecule targetMolecule, IMolecule mainMolecule){ List atoms=null; for (int i=0;i<addAtomContainer.getAtomCount();i++){ targetMolecule.addAtom(addAtomContainer.getAtom(i)); targetMolecule.addAtom(addAtomContainer.getAtom(i)); //Check for double bonds atoms=mainMolecule.getConnectedAtomsList(addAtomContainer.getAtom(i)); for (int j = 0; j < atoms.size(); j++) { IAtom atom = (IAtom)atoms.get(j); if (this.exocyclicDoubleBonds && mainMolecule.getBond(atom,addAtomContainer.getAtom(i)).getOrder()>1 && !targetMolecule.contains(atom)){ targetMolecule.addAtom(atom); } } } return targetMolecule; } /** * checks if the starting point and the end point of the shortest path are in the path * if true path is rejected * @param firstRingAtom IAtom start point * @param secondRingAtom IAtom end point * @param path IAtomContainer path * @return boolean true if path is reasonable */ private boolean checkPath(IAtom firstRingAtom, IAtom secondRingAtom, IAtomContainer path){ //logger.debug("CHECK PATH"); if (path.contains(firstRingAtom) || path.contains(secondRingAtom)){ return false; } return true; } /** * get starting points (IAtom) of possible linkers * @param ringAtom IAtom the ring atom * @param molecule IMolecule original molecule * @param ringSystem IAtomContainer the ring system * @return IAtomContainer possible starting points of linkers */ private IAtomContainer getPossibleLinkerSubstituents(IAtom ringAtom,IMolecule molecule, IAtomContainer ringSystem){ List atoms = molecule.getConnectedAtomsList(ringAtom); IAtomContainer substituents=new AtomContainer(); for (int i = 0; i<atoms.size();i++){ IAtom atom = (IAtom)atoms.get(i); if (!ringSystem.contains(atom)&& !atom.getSymbol().equals("H")){ substituents.addAtom(atom); } } return substituents; } /** * check for zero-Atom linkers * @param firstRingAtom IAtom of the first root atom * @param secondRingAtom IAtom of the second root atom * @param molecule IMolecule original molecule * @return boolean true for zero atom linker, eg in biphenyl systems */ private boolean zeroAtomLinker(IAtom firstRingAtom, IAtom secondRingAtom, IMolecule molecule){ List atoms= molecule.getConnectedAtomsList(firstRingAtom); if (atoms.contains(secondRingAtom)){ return true; }else{ return false;} } /** * @return String[] smiles of the murcko fragments */ public String[] getMurckoFrameworksAsSmileArray(){ SmilesGenerator sg =null; String[] murckoFragmentsmiles={}; if (this.murckoFragments !=null){ murckoFragmentsmiles=new String[this.murckoFragments.size()]; //logger.debug("SIZE OF MURCKO VECTOR:"+this.murckoFragments.size()); //logger.debug("SIZE OF SMILES[]:"+murckoFragmentsmiles.length); for (int i =0;i<this.murckoFragments.size();i++){ try{ IMolecule mol=(IMolecule)this.murckoFragments.get(i); if (ConnectivityChecker.isConnected(mol)){ sg = new SmilesGenerator(); if (smilesToUpperCase){ murckoFragmentsmiles[i]=sg.createSMILES(mol).toUpperCase(); }else{ murckoFragmentsmiles[i]=sg.createSMILES(mol); } }else{ logger.debug("ERROR in getMurckoFrameworksAsSmileArray due to:Molecule is not connected"); } } catch (Exception e){ logger.error("ERROR in getMurckoFrameworksAsSmileArray due to:"+e.toString()); logger.debug(e); } } } return murckoFragmentsmiles; } /** * @return String[] smiles of the ring fragments NOT WORKING */ public String[] getRingFragmentsAsSmileArray(){ SmilesGenerator sg =null; String[] ringFragmentSmiles={}; if (this.ringFragments !=null){ ringFragmentSmiles=new String[this.ringFragments.size()]; //logger.debug("SIZE OF MURCKO VECTOR:"+this.ringFragments.size()); //logger.debug("SIZE OF SMILES[]:"+ringFragmentSmiles.length); for (int i =0;i<this.ringFragments.size();i++){ try{ IMolecule mol=(IMolecule)this.ringFragments.get(i); sg = new SmilesGenerator(); if (smilesToUpperCase){ ringFragmentSmiles[i]=sg.createSMILES(mol).toUpperCase(); }else{ ringFragmentSmiles[i]=sg.createSMILES(mol); } } catch (Exception e){ logger.error("ERROR in smile generation due to:"+e.toString()); } } } return ringFragmentSmiles; } /** * @return String[] smiles of the linker fragments */ public String[] getLinkerFragmentsAsSmileArray(){ SmilesGenerator sg =null; String[] linkerFragmentSmiles={}; if (this.linkerFragments !=null){ linkerFragmentSmiles=new String[this.linkerFragments.size()]; //logger.debug("SIZE OF MURCKO VECTOR:"+this.ringFragments.size()); //logger.debug("SIZE OF SMILES[]:"+ringFragmentSmiles.length); for (int i =0;i<this.linkerFragments.size();i++){ try{ IMolecule mol=(IMolecule)this.linkerFragments.get(i); sg = new SmilesGenerator(); if (smilesToUpperCase){ linkerFragmentSmiles[i]=sg.createSMILES(mol).toUpperCase(); }else{ linkerFragmentSmiles[i]=sg.createSMILES(mol); } } catch (Exception e){ logger.error("ERROR in smile generation due to:"+e.toString()); } } } return linkerFragmentSmiles; } private void resetFlags(IMolecule molecule){ for (int i=0;i<molecule.getAtomCount();i++){ molecule.getAtom(i).setFlag(CDKConstants.VISITED, false); } } /** * @return Vector murckoFragments */ public List getMurckoFrameworks() { return this.murckoFragments; } /** * @return Vector ringFragments */ public List getRingFragments() { return this.ringFragments; } /** * @return Vector linkerFragments */ public List getLinkerFragments() { return this.linkerFragments; } public boolean isSmilesToUpperCase() { return smilesToUpperCase; } public void setSmilesToUpperCase(boolean smilesToUpperCase) { this.smilesToUpperCase = smilesToUpperCase; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -