@@ -860,6 +860,11 @@ else if (xa.getAtno() == 1) {
860
860
else if (chiral != 0 ) {
861
861
m .setChirality (i , 0 );
862
862
}
863
+
864
+ int ch = a .getCharge ();
865
+ if (ch < 0 ) {
866
+ a .setCharge (ch +1 );
867
+ }
863
868
} // endfor each atom
864
869
865
870
/*
@@ -1526,11 +1531,10 @@ else if (frags.length > 0) {
1526
1531
b .setFlags (f & MolBond .REACTING_CENTER_MASK ,
1527
1532
MolBond .REACTING_CENTER_MASK );
1528
1533
}
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 ))) {
1534
1538
int s = b .calcStereo2 ();
1535
1539
switch (s ) {
1536
1540
case MolBond .CIS :
@@ -2329,7 +2333,39 @@ void postprocessing (Molecule mol) {
2329
2333
net += a .getCharge ();
2330
2334
}
2331
2335
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
+
2333
2369
neg = 0 ; // leave the negative charges unchanged
2334
2370
}
2335
2371
}
@@ -2349,6 +2385,11 @@ void postprocessing (Molecule mol) {
2349
2385
*/
2350
2386
try {
2351
2387
String smiles = mol .toFormat ("cxsmiles:u" );
2388
+ if (debug ) {
2389
+ logger .log (Level .INFO , "Before final molecule cleaning: "
2390
+ +smiles );
2391
+ }
2392
+
2352
2393
Molecule newmol = MolImporter .importMol (smiles );
2353
2394
newmol .dearomatize ();
2354
2395
@@ -2523,7 +2564,11 @@ static void process (String tag, java.io.InputStream is, PrintStream os)
2523
2564
throws Exception {
2524
2565
MolImporter mi = new MolImporter (is );
2525
2566
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 );
2527
2572
LyChIStandardizer msz = new LyChIStandardizer (tg );
2528
2573
msz .removeSaltOrSolvent (true );
2529
2574
@@ -2554,16 +2599,8 @@ else if (tag == null) {
2554
2599
+ " has valence error!" );
2555
2600
}
2556
2601
2557
- /*
2558
- analyzer.setMolecule(mol);
2559
- double before = analyzer.exactMass();
2560
- */
2561
2602
int dim = mol .getDim ();
2562
2603
msz .standardize (mol );
2563
- /*
2564
- analyzer.setMolecule(m);
2565
- double after = analyzer.exactMass();
2566
- */
2567
2604
2568
2605
String smi = ChemUtil .canonicalSMILES (mol , true );
2569
2606
if (dim > 0 ) {
0 commit comments