?? deducebondsystemtool.java
字號:
/* $RCSfile: $
* $Author: egonw $
* $Date: 2006-04-20 17:59:04 -0400 (Thu, 20 Apr 2006) $
* $Revision: 6064 $
*
* Copyright (C) 2002-2007 The Chemistry Development Kit (CDK) project
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All I ask is that proper credit is given for my work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.smiles;
import java.util.ArrayList;
import java.util.List;
import org.openscience.cdk.Atom;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.Ring;
import org.openscience.cdk.RingSet;
import org.openscience.cdk.aromaticity.HueckelAromaticityDetector;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IRing;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.ringsearch.AllRingsFinder;
import org.openscience.cdk.ringsearch.SSSRFinder;
import org.openscience.cdk.tools.HydrogenAdder;
import org.openscience.cdk.tools.IValencyChecker;
import org.openscience.cdk.tools.LoggingTool;
import org.openscience.cdk.tools.SmilesValencyChecker;
/**
* Tool that tries to deduce bond orders based on connectivity and hybridization
* for a number of common ring systems.
*
* @author Todd Martin
* @cdk.module smiles
* @cdk.keyword bond order
*/
public class DeduceBondSystemTool {
private AllRingsFinder allRingsFinder;
private LoggingTool logger;
private HydrogenAdder hAdder;
private IValencyChecker valencyChecker;
private List listOfRings = null;
private int counter = 0;
private boolean interrupted;
/**
* Constructor for the DeduceBondSystemTool object.
*/
public DeduceBondSystemTool() {
allRingsFinder = new AllRingsFinder();
logger = new LoggingTool(this);
valencyChecker = new SmilesValencyChecker();
hAdder = new HydrogenAdder();
}
public boolean isOK(IMolecule m) throws CDKException {
IRingSet rs = allRingsFinder.findAllRings(m);
storeRingSystem(m, rs);
boolean StructureOK=this.isStructureOK(m);
IRingSet irs=this.removeExtraRings(m);
if (irs==null) throw new CDKException("error in AllRingsFinder.findAllRings");
int count=this.getBadCount(m,irs);
if (StructureOK && count==0) {
return true;
} else {
return false;
}
}
public IMolecule fixAromaticBondOrders(IMolecule molecule) throws CDKException {
//logger.debug("here");
IRingSet rs = allRingsFinder.findAllRings(molecule);
storeRingSystem(molecule, rs);
IRingSet ringSet = null;
// TODO remove rings with nonsp2 carbons(?) and rings larger than 7 atoms
ringSet = removeExtraRings(molecule);
if (ringSet==null) throw new CDKException("failure in AllRingsFinder.findAllRings");
ArrayList MasterList = new ArrayList();
//this.counter=0;// counter which keeps track of all current possibilities for placing double bonds
this.FixPyridineNOxides(molecule,ringSet);
for (int i = 0; i <= ringSet.getAtomContainerCount() - 1; i++) {
IRing ring = (IRing) ringSet.getAtomContainer(i);
if (ring.getAtomCount() == 5) {
fiveMemberedRingPossibilities(molecule, ring, MasterList);
} else if (ring.getAtomCount() == 6) {
sixMemberedRingPossibilities(molecule, ring, MasterList);
} else if (ring.getAtomCount() == 7){
sevenMemberedRingPossibilities(molecule, ring, MasterList);
//TODO- add code for all 7 membered aromatic ring possibilities not just 3 bonds
} else {
//TODO: what about other rings systems?
logger.debug("Found ring of size: " + ring.getAtomCount());
}
}
IMoleculeSet som = molecule.getBuilder().newMoleculeSet();
// int number=1; // total number of possibilities
//
// for (int ii=0;ii<=MasterList.size()-1;ii++) {
// ArrayList ringlist=(ArrayList)MasterList.get(ii);
// number*=ringlist.size();
// }
// logger.debug("number= "+number);
int [] choices = null;
//if (number> 1000000) return null;
choices = new int [MasterList.size()];
if (MasterList.size() > 0) {
IMolecule iMolecule = loop(System.currentTimeMillis(), molecule, 0, MasterList, choices, som);
if (iMolecule instanceof IMolecule) return iMolecule;
}
int mincount = 99999999;
int best = -1; // one with minimum number of bad atoms
// minimize number of potentially bad nitrogens among molecules in the set
for (int i = 0; i <= som.getAtomContainerCount() - 1; i++) {
IMolecule mol = som.getMolecule(i);
ringSet = removeExtraRings(mol);
if (ringSet==null) continue;
int count = getBadCount(mol, ringSet);
//logger.debug(i + "\t" + count);
if (count < mincount) {
mincount = count;
best = i;
}
}
if (som.getAtomContainerCount() > 0) return som.getMolecule(best);
return molecule;
}
private void FixPyridineNOxides(IMolecule molecule,IRingSet ringSet) {
//convert n(=O) to [n+][O-]
for (int i=0;i<molecule.getAtomCount();i++) {
IAtom ai=molecule.getAtom(i);
if (ai.getSymbol().equals("N") && ai.getFormalCharge()==0) {
if (inRingSet(ai,ringSet)) {
List ca=molecule.getConnectedAtomsList(ai);
for (int j=0;j<ca.size();j++){
IAtom caj=(IAtom)ca.get(j);
if (caj.getSymbol().equals("O") && molecule.getBond(ai,caj).getOrder()==2) {
ai.setFormalCharge(1);
caj.setFormalCharge(-1);
molecule.getBond(ai,caj).setOrder(1);
}
}// end for (int j=0;j<ca.size();j++)
} // end if (inRingSet(ai,ringSet)) {
} // end if (ai.getSymbol().equals("N") && ai.getFormalCharge()==0)
} // end for (int i=0;i<molecule.getAtomCount();i++)
}
private void applyBonds(IMolecule m, ArrayList al) {
//logger.debug("");
for (int i = 0; i <= al.size() - 1; i++) {
String s = (String) al.get(i);
String s1 = s.substring(0, s.indexOf("-"));
String s2 = s.substring(s.indexOf("-") + 1, s.length());
int i1 = Integer.parseInt(s1);
int i2 = Integer.parseInt(s2);
//logger.debug(s1+"\t"+s2);
IBond b = m.getBond(m.getAtom(i1), m.getAtom(i2));
b.setOrder(2);
}
}
private void fiveMemberedRingPossibilities(IMolecule m, IRing r, ArrayList MasterList) {
// 5 possibilities for placing 2 double bonds
// 5 possibilities for placing 1 double bond
int [] num = new int [5]; // stores atom numbers based on atom numbers in molecule instead of ring
for (int j = 0; j <= 4; j++) {
num[j] = m.getAtomNumber(r.getAtom(j));
//logger.debug(num[j]);
}
java.util.ArrayList al1 = new java.util.ArrayList();
java.util.ArrayList al2 = new java.util.ArrayList();
java.util.ArrayList al3 = new java.util.ArrayList();
java.util.ArrayList al4 = new java.util.ArrayList();
java.util.ArrayList al5 = new java.util.ArrayList();
java.util.ArrayList al6 = new java.util.ArrayList();
java.util.ArrayList al7 = new java.util.ArrayList();
java.util.ArrayList al8 = new java.util.ArrayList();
java.util.ArrayList al9 = new java.util.ArrayList();
java.util.ArrayList al10 = new java.util.ArrayList();
al1.add(num[1] + "-" + num[2]);
al1.add(num[3] + "-" + num[4]);
al2.add(num[2] + "-" + num[3]);
al2.add(num[0] + "-" + num[4]);
al3.add(num[0] + "-" + num[1]);
al3.add(num[3] + "-" + num[4]);
al4.add(num[0] + "-" + num[4]);
al4.add(num[1] + "-" + num[2]);
al5.add(num[0] + "-" + num[1]);
al5.add(num[2] + "-" + num[3]);
al6.add(num[0] + "-" + num[1]);
al7.add(num[1] + "-" + num[2]);
al8.add(num[2] + "-" + num[3]);
al9.add(num[3] + "-" + num[4]);
al10.add(num[4] + "-" + num[0]);
ArrayList mal = new ArrayList();
mal.add(al1);
mal.add(al2);
mal.add(al3);
mal.add(al4);
mal.add(al5);
mal.add(al6);
mal.add(al7);
mal.add(al8);
mal.add(al9);
mal.add(al10);
// mal.add(al11);
MasterList.add(mal);
}
private void sixMemberedRingPossibilities(IMolecule m, IRing r, ArrayList MasterList) {
// 2 possibilities for placing 3 double bonds
// 6 possibilities for placing 2 double bonds
// 6 possibilities for placing 1 double bonds
IAtom [] ringatoms = new Atom [6];
ringatoms[0] = r.getAtom(0);
int [] num = new int [6];
for (int j = 0; j <= 5; j++) {
num[j] = m.getAtomNumber(r.getAtom(j));
}
java.util.ArrayList al1 = new java.util.ArrayList();
java.util.ArrayList al2 = new java.util.ArrayList();
al1.add(num[0] + "-" + num[1]);
al1.add(num[2] + "-" + num[3]);
al1.add(num[4] + "-" + num[5]);
al2.add(num[1] + "-" + num[2]);
al2.add(num[3] + "-" + num[4]);
al2.add(num[5] + "-" + num[0]);
java.util.ArrayList al3 = new java.util.ArrayList();
java.util.ArrayList al4 = new java.util.ArrayList();
java.util.ArrayList al5 = new java.util.ArrayList();
java.util.ArrayList al6 = new java.util.ArrayList();
java.util.ArrayList al7 = new java.util.ArrayList();
java.util.ArrayList al8 = new java.util.ArrayList();
java.util.ArrayList al9 = new java.util.ArrayList();
java.util.ArrayList al10 = new java.util.ArrayList();
java.util.ArrayList al11 = new java.util.ArrayList();
java.util.ArrayList al12 = new java.util.ArrayList();
java.util.ArrayList al13 = new java.util.ArrayList();
java.util.ArrayList al14 = new java.util.ArrayList();
java.util.ArrayList al15 = new java.util.ArrayList();
java.util.ArrayList al16 = new java.util.ArrayList();
java.util.ArrayList al17 = new java.util.ArrayList();
java.util.ArrayList al18 = new java.util.ArrayList();
al3.add(num[0] + "-" + num[1]);
al3.add(num[2] + "-" + num[3]);
al4.add(num[0] + "-" + num[1]);
al4.add(num[4] + "-" + num[5]);
al5.add(num[1] + "-" + num[2]);
al5.add(num[3] + "-" + num[4]);
al6.add(num[1] + "-" + num[2]);
al6.add(num[0] + "-" + num[5]);
al7.add(num[2] + "-" + num[3]);
al7.add(num[4] + "-" + num[5]);
al8.add(num[0] + "-" + num[5]);
al8.add(num[3] + "-" + num[4]);
al9.add(num[0] + "-" + num[1]);
al9.add(num[3] + "-" + num[4]);
al10.add(num[1] + "-" + num[2]);
al10.add(num[4] + "-" + num[5]);
al11.add(num[2] + "-" + num[3]);
al11.add(num[0] + "-" + num[5]);
al12.add(num[0] + "-" + num[1]);
al13.add(num[1] + "-" + num[2]);
al14.add(num[2] + "-" + num[3]);
al15.add(num[3] + "-" + num[4]);
al16.add(num[4] + "-" + num[5]);
al17.add(num[5] + "-" + num[0]);
ArrayList mal = new ArrayList();
mal.add(al1);
mal.add(al2);
mal.add(al3);
mal.add(al4);
mal.add(al5);
mal.add(al6);
mal.add(al7);
mal.add(al8);
mal.add(al9);
mal.add(al10);
mal.add(al11);
mal.add(al12);
mal.add(al13);
mal.add(al14);
mal.add(al15);
mal.add(al16);
mal.add(al17);
mal.add(al18);
MasterList.add(mal);
}
private void sevenMemberedRingPossibilities(IMolecule m, IRing r, ArrayList MasterList) {
// for now only consider case where have 3 double bonds
IAtom[] ringatoms = new Atom[7];
ringatoms[0] = r.getAtom(0);
int[] num = new int[7];
for (int j = 0; j <= 6; j++) {
num[j] = m.getAtomNumber(r.getAtom(j));
}
java.util.ArrayList al1 = new java.util.ArrayList();
java.util.ArrayList al2 = new java.util.ArrayList();
java.util.ArrayList al3 = new java.util.ArrayList();
java.util.ArrayList al4 = new java.util.ArrayList();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -