Skip to content

Commit 8aee571

Browse files
committed
bugfix
1 parent 18ab319 commit 8aee571

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

src/main/java/com/actelion/research/chem/AromaticityResolver.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public boolean locateDelocalizedDoubleBonds(boolean[] isDelocalizedBond, boolean
112112

113113
promoteObviousBonds();
114114

115-
while (promoteOuterShellDelocalizedRingSystems(ringSet))
115+
while (promoteOuterShellDelocalizedRingSystems(ringSet, mayChangeAtomCharges))
116116
promoteObviousBonds();
117117

118118
// try to find and promote entirely aromatic 6-rings
@@ -136,16 +136,22 @@ public boolean locateDelocalizedDoubleBonds(boolean[] isDelocalizedBond, boolean
136136
if (mDelocalizedAtoms - mPiElectronsAdded >= 2)
137137
connectSeparatedSingletons();
138138

139-
if (mayChangeAtomCharges) {
140-
for (int atom=0; atom<mMol.getAtoms(); atom++) {
141-
if (mIsDelocalizedAtom[atom] && mMol.getImplicitHydrogens(atom) != 0) {
142-
if ((mMol.getAtomCharge(atom) == 1 && mMol.isElectronegative(atom))
143-
|| (mMol.getAtomCharge(atom) == -1 && mMol.getAtomicNo(atom) == 5))
144-
mMol.setAtomCharge(atom, 0);
145-
else
146-
mMol.setAtomRadical(atom, Molecule.cAtomRadicalStateD);
147-
mPiElectronsAdded++;
148-
}
139+
// If finally one or more single delocalized atoms remain, and if these carry an implicit hydrogen,
140+
// and if it is allowed and possible, then add/remove a charge to make the atom's lone pair contribute
141+
// to the neighbour atom's delocalization. If modifying charges is not allowed, then remove an implicit
142+
// hydrogen including one of its binding electrons. An unpaired electron is closer to the intended aromatic
143+
// state than a wrong hybridisation and one implicit hydrogen too much.
144+
// In addition, during id-coordinate parsing of implicit hydrogen atoms, the number of implicit hydrogens
145+
// per non-H atom must exactly match the one given when the idcode with coordinates was encoded.
146+
for (int atom=0; atom<mMol.getAtoms(); atom++) {
147+
if (mIsDelocalizedAtom[atom] && mMol.getImplicitHydrogens(atom) != 0) {
148+
if (mayChangeAtomCharges
149+
&& ((mMol.getAtomCharge(atom) == 1 && mMol.isElectronegative(atom))
150+
|| (mMol.getAtomCharge(atom) == -1 && mMol.getAtomicNo(atom) == 5)))
151+
mMol.setAtomCharge(atom, 0);
152+
else
153+
mMol.setAtomRadical(atom, Molecule.cAtomRadicalStateD);
154+
mPiElectronsAdded++;
149155
}
150156
}
151157

@@ -229,7 +235,7 @@ private boolean promoteSixMemberedAromaticRings(RingCollection ringSet, boolean
229235

230236
if (isQualifyingRing) {
231237
if (mayChangeAtomCharges)
232-
for (int i=0; i<6; i+=2)
238+
for (int i=0; i<6; i++)
233239
checkAtomTypePi1(ringAtom[i], true);
234240

235241
for (int i=0; i<6; i+=2)
@@ -286,7 +292,7 @@ private boolean promoteOneDelocalizationLeak(RingCollection ringSet, boolean may
286292
return false;
287293
}
288294

289-
private boolean promoteOuterShellDelocalizedRingSystems(RingCollection ringSet) {
295+
private boolean promoteOuterShellDelocalizedRingSystems(RingCollection ringSet, boolean mayChangeAtomCharges) {
290296
int[] sharedDelocalizedRingCount = new int[mMol.getBonds()];
291297
for (int r=0; r<ringSet.getSize(); r++) {
292298
int[] ringBond = ringSet.getRingBonds(r);
@@ -325,6 +331,10 @@ private boolean promoteOuterShellDelocalizedRingSystems(RingCollection ringSet)
325331
if (bridgeBonds > 2 && (bridgeBonds & 1) == 1) {
326332
for (int j=1; j<bridgeBonds; j+=2) {
327333
int index = (first+j < ringBond.length) ? first+j : first+j-ringBond.length;
334+
if (mayChangeAtomCharges) {
335+
checkAtomTypePi1(ringAtom[index], true);
336+
checkAtomTypePi1(ringAtom[index == ringAtom.length-1 ? 0 : index+1], true);
337+
}
328338
promoteBond(ringBond[index]);
329339
}
330340
found = true;

src/main/java/com/actelion/research/chem/io/pdb/parser/PDBFileParser.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.io.*;
4141
import java.net.URI;
4242
import java.net.URLConnection;
43+
import java.nio.charset.StandardCharsets;
4344
import java.text.DateFormat;
4445
import java.text.ParseException;
4546
import java.text.SimpleDateFormat;
@@ -199,38 +200,32 @@ public PDBCoordEntryFile getFromPDB(String pdbID) throws Exception {
199200
}
200201

201202
public PDBFileParser() {
202-
203203
dfDateDeposition = new SimpleDateFormat(DATE_FORMAT);
204-
205204
RemarkParser remarkParser = new RemarkParser();
206-
207205
hetNameParser = new HetNameParser();
208-
209206
hetSynonymParser = new HetSynonymParser();
210-
211207
formulaParser = new FormulaParser();
212-
213208
siteParser = new SiteParser();
214-
215209
modelParser = new ModelParser();
216-
217210
}
218211

219212
public PDBCoordEntryFile parse(File fiPDB) throws IOException, ParseException {
220-
return parse(new BufferedReader(new FileReader(fiPDB)));
213+
InputStream stream = fiPDB.getName().toLowerCase().endsWith(".pdb.gz") ?
214+
new GZIPInputStream(new FileInputStream(fiPDB))
215+
: new FileInputStream(fiPDB);
216+
return parse(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)));
221217
}
222218

223219
public PDBCoordEntryFile parse(BufferedReader br) throws IOException, ParseException {
224220
PDBCoordEntryFile pdbCoordEntryFile = new PDBCoordEntryFile();
225221

226-
ArrayList<String> liRaw = new ArrayList<String>();
222+
ArrayList<String> liRaw = new ArrayList<>();
227223

228224
String sCurrentLine;
229225
while ((sCurrentLine = br.readLine()) != null) {
230226
liRaw.add(sCurrentLine);
231227
}
232228

233-
234229
int indexLine = 0;
235230

236231
String lHeader = liRaw.get(indexLine);

0 commit comments

Comments
 (0)