水素結合ドナー

前回のコードを改造して、
ドナー(水素を供与する側の原子)の数も同時に数えてみましょう。
定義は、アクセプターより単純です。

  • 酸素もしくは窒素原子のうち、水素原子に隣接し、しかも負電荷を帯びていないもの

ID, アクセプター数、ドナー数をタブ区切りで出力してみます。


/* HBAccDon.java */

import java.io.*;
import org.openscience.cdk.io.iterator.IteratingSMILESReader;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;


class HBAccDon {
public static void main(String args[]){

if(args.length!=1){
System.err.println("HBAccDon <smiles-file>");
System.exit(1);
}
FileInputStream fis = null;
IteratingSMILESReader isr = null;
try{
fis = new FileInputStream(new File(args[0]));
isr = new IteratingSMILESReader(fis);
} catch (Exception e) {
e.printStackTrace();
}

while( isr.hasNext() ){ // Read a file line by line
IMolecule imol = (IMolecule)isr.next();
String id = (String)imol.getProperty("cdk:Title"); // The 2nd column

int hBondAcceptors = 0;
IAtomContainer ac;
try {

ac = (IAtomContainer) imol.clone();
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac);
CDKHueckelAromaticityDetector.detectAromaticity(ac);

atomloop:
for (int atomIndex = 0; atomIndex < ac.getAtomCount(); atomIndex++) {
// looking for suitable nitrogen atoms
if (ac.getAtom(atomIndex).getSymbol().equals("N") &&
ac.getAtom(atomIndex).getFormalCharge() <= 0) {
// excluding nitrogens that are adjacent to an oxygen
java.util.List neighbours =
ac.getConnectedAtomsList(ac.getAtom(atomIndex));
for (Object neighbour : neighbours)
if (((IAtom) neighbour).getSymbol().equals("O"))
continue atomloop;
hBondAcceptors++;
}
// looking for suitable oxygen atoms
if (ac.getAtom(atomIndex).getSymbol().equals("O") &&
ac.getAtom(atomIndex).getFormalCharge() <= 0) {
//excluding oxygens that are adjacent to a nitrogen or to an aromatic carbon

java.util.List neighbours = ac.getConnectedAtomsList(ac.getAtom(atomIndex));
for (Object neighbour : neighbours)
if (((IAtom) neighbour).getSymbol().equals("N") ||
(((IAtom) neighbour).getSymbol().equals("C")
&& ((IAtom) neighbour ).getFlag(CDKConstants.ISAROMATIC)))

continue atomloop;
hBondAcceptors++;
}
}

int hBondDonors = 0;
atomloop2:
for (int atomIndex = 0; atomIndex < ac.getAtomCount(); atomIndex++) {
IAtom atom = (IAtom) ac.getAtom(atomIndex);
// checking for O and N atoms where the formal charge is >= 0
if ( (atom.getSymbol().equals("O") || atom.getSymbol().equals("N"))
&& atom.getFormalCharge() >= 0) {
// implicit hydrogens
Integer implicitH = atom.getHydrogenCount();
if (implicitH == CDKConstants.UNSET) implicitH = 0;
if (implicitH > 0) {
hBondDonors++;
continue atomloop2;
}
// explicit hydrogens
java.util.List neighbours = ac.getConnectedAtomsList(atom);
for (Object neighbour : neighbours) {
if (((IAtom) neighbour).getSymbol().equals("H")) {
hBondDonors++;
continue atomloop2;
}
}
}
}

System.out.printf("%s\t%d\t%d\n", id, hBondAcceptors, hBondDonors);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}