[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reaction binary format throws away stereo chemistry #1257

Open
bp-kelley opened this issue Jan 9, 2017 · 4 comments
Open

Reaction binary format throws away stereo chemistry #1257

bp-kelley opened this issue Jan 9, 2017 · 4 comments
Labels

Comments

@bp-kelley
Copy link
Contributor

Rxn block below - product is a glucose

sugar.rxn
  ChemDraw01091716252D

  0  1
$MOL



 12 12  0  0  0  0  0  0  0  0999 V2000
   -1.6271    1.1845    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7537    0.4787    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7537   -0.4785    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.1555    0.9572    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.1555   -0.9631    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.3460   -0.9631    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.1555    1.9263    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    0.4367    0.4787    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
   -0.1555   -1.9263    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    0.4367   -0.4785    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.0349   -0.9631    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.6271   -0.4785    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
  2  1  1  1        0
  2  3  1  0        0
  2  4  1  0        0
  3  5  1  0        0
  3  6  1  6        0
  4  7  1  1        0
  4  8  1  0        0
  5  9  1  6        0
  5 10  1  0        0
 10  8  1  0        0
 10 11  1  6        0
 11 12  1  0        0
M  END

Test

rxn = AllChem.ReactionFromRxnBlock(open("sugar.rxn").read())
for prod in rxn.GetProducts():
    s = Chem.MolToSmiles(prod, isomericSmiles=True)

rxn = AllChem.ChemicalReaction(rxn.ToBinary())

for prod in rxn.GetProducts():
    s2 = Chem.MolToSmiles(prod, isomericSmiles=True)
    assert s == s2, "%s %s"%(s, s2)

output

AssertionError: [H]C1[C@@H](O)[C@@H](O)O[C@H](CO)[C@@H]1O [H]C1C(O)C(O)OC(CO)C1O
@bp-kelley
Copy link
Contributor Author

FileParserUtils::replaceAtomWithQueryAtom appears to be the culprit here.

void testReplaceAtom() {
  const char *stereo_mol = "\n" \
"\n" \
"\n" \
" 18 19  0  0  0  0  0  0  0  0999 V2000\n" \
"   -0.9724    1.1105    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -0.1323    0.4316    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -0.1323   -0.4891    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"    0.4431    0.8919    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"    0.4431   -0.9552    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -0.7020   -0.9552    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"    0.4431    1.8240    0.0000 S   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"    1.0127    0.4316    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"    0.4431   -1.8816    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"    1.0127   -0.4891    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -0.9149   -1.8240    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -1.2256   -0.3855    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -0.1323    2.2843    0.0000 R1  0  0  0  0  0  0  0  0  0  0  0  0\n" \
"    1.5881   -0.9552    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -1.5824   -1.8240    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -1.7780   -0.9552    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"    2.1578   -0.4891    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0\n" \
"   -2.1578   -2.2843    0.0000 R2  0  0  0  0  0  0  0  0  0  0  0  0\n" \
"  2  1  1  1        0\n" \
"  2  3  1  0        0\n" \
"  2  4  1  0        0\n" \
"  3  5  1  0        0\n" \
"  3  6  1  6        0\n" \
"  4  7  1  1        0\n" \
"  4  8  1  0        0\n" \
"  5  9  1  6        0\n" \
"  5 10  1  0        0\n" \
"  6 11  1  0        0\n" \
"  6 12  1  0        0\n" \
"  7 13  1  0        0\n" \
" 10  8  1  0        0\n" \
" 10 14  1  6        0\n" \
" 11 15  2  0        0\n" \
" 12 16  2  0        0\n" \
" 14 17  1  0        0\n" \
" 15 16  1  0        0\n" \
" 15 18  1  0        0\n" \
"M  END\n";

  RWMol *mol = MolBlockToMol(stereo_mol);
  std::string csmi1 = MolToSmiles(*mol, true);
  for (ROMol::AtomIterator atomIt = mol->beginAtoms();
       atomIt != mol->endAtoms(); ++atomIt) {
    FileParserUtils::replaceAtomWithQueryAtom(mol,
                                              (*atomIt));
  }
  std::string csmi2 = MolToSmiles(*mol, true);
  TEST_ASSERT(csmi1 == csmi2);

  
  std::ostringstream ss;
  MolPickler::pickleMol(*mol, ss);
  std::istringstream ss2(ss.str());
  ROMol *mol2 = new ROMol();
  MolPickler::molFromPickle(ss2, *mol2);
  csmi2 = MolToSmiles(*mol2, true);
  TEST_ASSERT(csmi1 == csmi2);
  std::cerr << csmi1 << std::endl;
  std::cerr << csmi2 << std::endl;
  delete mol;  
}

@bp-kelley
Copy link
Contributor Author

I'm at a loss. When reading a mol block product's atoms are converted to queries, however this means that most of the properties (hybdidization/chirality/etc) won't be pickled.

One thing we could do is keep a copy of the original products when coming from an MDL File and pickle them. On unpickling, if the products atom's doesn't have queries, call the replaceAtomWithQuery.

@bp-kelley
Copy link
Contributor Author

@greglandrum Ok, here is what I think the problem is. The pickling expects an atom to either be a normal atom or a query. For the reactions they appear to be used as both so the pickling is busted. Note that this also happens for ReactionFromSmarts.

Pickling both pieces of information is apparently not possible without a bit of effort...

bp-kelley pushed a commit to bp-kelley/rdkit that referenced this issue Jan 23, 2017
Copy link
Contributor

This issue was marked as stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant