Skip to content

Commit f929ace

Browse files
committed
Make ALogP work with implicit hydrogens, we can now also avoid the clone.
1 parent a192d17 commit f929ace

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

base/atomtype/src/main/java/org/openscience/cdk/atomtype/EStateAtomTypeMatcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public IAtomType findMatchingAtomType(IAtomContainer atomContainer, IAtom atom)
6363
IAtomType atomType = null;
6464
try {
6565
String fragment = "";
66-
int NumHAtoms = 0;
67-
int NumSingleBonds2 = 0;
66+
int NumHAtoms = atom.getImplicitHydrogenCount();
67+
int NumSingleBonds2 = NumHAtoms;
6868
int NumDoubleBonds2 = 0;
6969
int NumTripleBonds2 = 0;
7070
int NumAromaticBonds2 = 0;

descriptor/qsarmolecular/src/main/java/org/openscience/cdk/qsar/descriptors/molecular/ALOGPDescriptor.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ private double[] calculate(IAtomContainer atomContainer, String[] fragment, IRin
392392
frags[i] = 0;
393393
}
394394

395-
for (int i = 0; i <= atomContainer.getAtomCount() - 1; i++) {
395+
for (int i = 0; i < atomContainer.getAtomCount(); i++) {
396396
// alogpfrag[i] = 0; // not needed (new array initalized above)
397397
try {
398398
if (fragment[i] != null) {
@@ -469,7 +469,9 @@ private void calcGroup001_005(int i) {
469469
// C in CH3R
470470
if (fragment[i].equals("SsCH3")) {
471471
List<IAtom> ca = atomContainer.getConnectedAtomsList(atomContainer.getAtom(i));
472-
int htype = getHAtomType(atomContainer.getAtom(i), ca);
472+
IAtom atom = atomContainer.getAtom(i);
473+
int htype = getHAtomType(atom, ca);
474+
frags[htype] += atom.getImplicitHydrogenCount();
473475
for (int j = 0; j < ca.size(); j++) {
474476
if (ca.get(j).getSymbol().equals("C")) {
475477
frags[1]++;
@@ -493,8 +495,11 @@ private void calcGroup002_006_007(int i) {
493495

494496
if (fragment[i].equals("SssCH2")) {
495497

496-
List<IAtom> nbors = atomContainer.getConnectedAtomsList(atomContainer.getAtom(i));
497-
int htype = getHAtomType(atomContainer.getAtom(i), nbors);
498+
IAtom atom = atomContainer.getAtom(i);
499+
List<IAtom> nbors = atomContainer.getConnectedAtomsList(atom);
500+
int htype = getHAtomType(atom, nbors);
501+
frags[htype] += atom.getImplicitHydrogenCount();
502+
498503
int carbonCount = 0;
499504
int heteroCount = 0;
500505
// logger.debug("here");
@@ -528,8 +533,11 @@ private void calcGroup003_008_009_010(int i) {
528533

529534
if (fragment[i].equals("SsssCH")) {
530535

531-
List ca = atomContainer.getConnectedAtomsList(atomContainer.getAtom(i));
532-
int htype = getHAtomType(atomContainer.getAtom(i), ca);
536+
IAtom atom = atomContainer.getAtom(i);
537+
List ca = atomContainer.getConnectedAtomsList(atom);
538+
int htype = getHAtomType(atom, ca);
539+
frags[htype] += atom.getImplicitHydrogenCount();
540+
533541
int carbonCount = 0;
534542
int heteroCount = 0;
535543
// logger.debug("here");
@@ -822,7 +830,10 @@ private void calcGroup024_027_030_033_042(int i) {
822830
IAtom ca0;
823831
IAtom ca1;
824832
// determine which neighbor is the H atom
825-
if (nbors.get(0).getAtomicNumber() == 1) {
833+
if (atom.getImplicitHydrogenCount() == 1) {
834+
ca0 = nbors.get(0);
835+
ca1 = nbors.get(1);
836+
} else if (nbors.get(0).getAtomicNumber() == 1) {
826837
alogpfrag[atomContainer.indexOf(nbors.get(0))] = htype;
827838
ca0 = nbors.get(1);
828839
ca1 = nbors.get(2);
@@ -1293,18 +1304,20 @@ private void calcGroup059_060_063(int i) {
12931304
}
12941305

12951306
private void calcGroup066_to_079(int i) {
1296-
int nAr = 0;
1297-
int nAl = 0;
1298-
IAtom ai = atomContainer.getAtom(i);
1307+
int nAr = 0;
1308+
int nAl = 0;
1309+
IAtom atom = atomContainer.getAtom(i);
1310+
IAtom ai = atom;
12991311
if (!ai.getSymbol().equals("N")) return;
1300-
List<IAtom> nbors = atomContainer.getConnectedAtomsList(atomContainer.getAtom(i));
1312+
List<IAtom> nbors = atomContainer.getConnectedAtomsList(atom);
13011313

13021314
int htype = 50; //H atom attached to a hetero atom
13031315
for (IAtom nbor : nbors)
13041316
if (nbor.getAtomicNumber() == 1) {
13051317
alogpfrag[nbor.getIndex()] = htype;
13061318
frags[htype]++;
13071319
}
1320+
frags[htype] += atom.getImplicitHydrogenCount();
13081321

13091322
for (int j = 0; j <= nbors.size() - 1; j++) {
13101323
if (((IAtom) nbors.get(j)).getSymbol().equals("H")) continue;
@@ -1800,8 +1813,8 @@ private void calcGroup101_to_104(int i) {
18001813
}
18011814

18021815
private boolean isBondedToHydrogenOnly(IAtom ai) {
1803-
return ai.getBondCount() == 1 &&
1804-
ai.bonds().iterator().next().getOther(ai).getAtomicNumber() == 1;
1816+
return ai.getBondCount() == 0 && ai.getImplicitHydrogenCount() == 1 ||
1817+
ai.getBondCount() == 1 && ai.bonds().iterator().next().getOther(ai).getAtomicNumber() == 1;
18051818
}
18061819

18071820
private void calcGroup106(int i) {
@@ -2037,15 +2050,7 @@ private boolean inSameAromaticRing(IAtomContainer atomContainer, IAtom atom1, IA
20372050
* @return the result of the calculation
20382051
*/
20392052
@Override
2040-
public DescriptorValue calculate(IAtomContainer atomContainer) {
2041-
IAtomContainer container;
2042-
try {
2043-
container = atomContainer.clone();
2044-
AtomContainerManipulator.convertImplicitToExplicitHydrogens(container);
2045-
} catch (CloneNotSupportedException e) {
2046-
return getDummyDescriptorValue(new CDKException("Error during clone"));
2047-
}
2048-
2053+
public DescriptorValue calculate(IAtomContainer container) {
20492054
IRingSet rs;
20502055
try {
20512056
AllRingsFinder arf = new AllRingsFinder();
@@ -2082,6 +2087,7 @@ public DescriptorValue calculate(IAtomContainer atomContainer) {
20822087
try {
20832088
ret = calculate(container, fragment, rs);
20842089
} catch (CDKException e) {
2090+
e.printStackTrace();
20852091
return getDummyDescriptorValue(new CDKException(e.getMessage()));
20862092
}
20872093

@@ -2105,7 +2111,7 @@ private DescriptorValue getDummyDescriptorValue(Exception e) {
21052111

21062112
/**
21072113
* Returns the specific type of the DescriptorResult object.
2108-
*
2114+
*
21092115
* The return value from this method really indicates what type of result will
21102116
* be obtained from the {@link org.openscience.cdk.qsar.DescriptorValue} object. Note that the same result
21112117
* can be achieved by interrogating the {@link org.openscience.cdk.qsar.DescriptorValue} object; this method

0 commit comments

Comments
 (0)