Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 7573d8e

Browse files
committed
turn on initial support keto-enol tautomerism (#11); still experimental
1 parent d4f1b5e commit 7573d8e

21 files changed

+6206
-15
lines changed

src/lychi/LyChIStandardizer.java

+52-15
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,11 @@ else if (xa.getAtno() == 1) {
860860
else if (chiral != 0) {
861861
m.setChirality(i, 0);
862862
}
863+
864+
int ch = a.getCharge();
865+
if (ch < 0) {
866+
a.setCharge(ch+1);
867+
}
863868
} // endfor each atom
864869

865870
/*
@@ -1526,11 +1531,10 @@ else if (frags.length > 0) {
15261531
b.setFlags(f & MolBond.REACTING_CENTER_MASK,
15271532
MolBond.REACTING_CENTER_MASK);
15281533
}
1529-
1530-
if (b.getType() == 2
1531-
&& !(b.getAtom1().isTerminalAtom()
1532-
|| b.getAtom2().isTerminalAtom())
1533-
&& !mol.isRingBond(mol.indexOf(b))) {
1534+
else if (b.getType() == 2
1535+
&& !(b.getAtom1().isTerminalAtom()
1536+
|| b.getAtom2().isTerminalAtom())
1537+
&& !mol.isRingBond(mol.indexOf(b))) {
15341538
int s = b.calcStereo2();
15351539
switch (s) {
15361540
case MolBond.CIS:
@@ -2329,7 +2333,39 @@ void postprocessing (Molecule mol) {
23292333
net += a.getCharge();
23302334
}
23312335

2332-
if (net >= 0) {
2336+
if (net > 0) {
2337+
// now see if we can add electrons to make this
2338+
// a zwitterion
2339+
MolAtom[] atoms = mol.getAtomArray();
2340+
int[] rank = new int[atoms.length];
2341+
mol.getGrinv(rank);
2342+
2343+
List<Integer> cand = new ArrayList<Integer>();
2344+
for (int i = 0; i < atoms.length; ++i) {
2345+
int ch = atoms[i].getCharge();
2346+
int hc = atoms[i].getImplicitHcount();
2347+
if (atoms[i].getAtno() == 8 && hc > 0 && ch == 0) {
2348+
cand.add(i);
2349+
}
2350+
}
2351+
2352+
while (net > 0 && !cand.isEmpty()) {
2353+
int minrank = Integer.MAX_VALUE;
2354+
Integer atom = null;
2355+
for (Integer a : cand) {
2356+
if (rank[a] < minrank) {
2357+
minrank = rank[a];
2358+
atom = a;
2359+
}
2360+
}
2361+
2362+
if (atom != null) {
2363+
cand.remove(atom);
2364+
atoms[atom].setCharge(-1);
2365+
--net;
2366+
}
2367+
}
2368+
23332369
neg = 0; // leave the negative charges unchanged
23342370
}
23352371
}
@@ -2349,6 +2385,11 @@ void postprocessing (Molecule mol) {
23492385
*/
23502386
try {
23512387
String smiles = mol.toFormat("cxsmiles:u");
2388+
if (debug) {
2389+
logger.log(Level.INFO, "Before final molecule cleaning: "
2390+
+smiles);
2391+
}
2392+
23522393
Molecule newmol = MolImporter.importMol(smiles);
23532394
newmol.dearomatize();
23542395

@@ -2523,7 +2564,11 @@ static void process (String tag, java.io.InputStream is, PrintStream os)
25232564
throws Exception {
25242565
MolImporter mi = new MolImporter (is);
25252566

2526-
TautomerGenerator tg = new SayleDelanyTautomerGenerator ();
2567+
TautomerGenerator tg =
2568+
// new NCGCTautomerGenerator ()
2569+
new SayleDelanyTautomerGenerator
2570+
// hanlding keto-enol... might be too slow
2571+
(1001, SayleDelanyTautomerGenerator.FLAG_ALL);
25272572
LyChIStandardizer msz = new LyChIStandardizer (tg);
25282573
msz.removeSaltOrSolvent(true);
25292574

@@ -2554,16 +2599,8 @@ else if (tag == null) {
25542599
+ " has valence error!");
25552600
}
25562601

2557-
/*
2558-
analyzer.setMolecule(mol);
2559-
double before = analyzer.exactMass();
2560-
*/
25612602
int dim = mol.getDim();
25622603
msz.standardize(mol);
2563-
/*
2564-
analyzer.setMolecule(m);
2565-
double after = analyzer.exactMass();
2566-
*/
25672604

25682605
String smi = ChemUtil.canonicalSMILES (mol, true);
25692606
if (dim > 0) {

0 commit comments

Comments
 (0)