The following is one of a whole list of molecules which Mathematica fails to export to PDB:

mol = Molecule[
    IncludeHydrogens -> True

ExportString[mol, {"PDB", "Molecule"}]
(* $Failed *)

But rdkit manages to export it correctly:

Python 3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 22:54:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> from rdkit import Chem
>>> from rdkit.Chem import AllChem
>>> mol = Chem.MolFromSmiles("CC1=CC(C2=CC(CC(=O)C3=CC=C(C)C(CC4=NC=CC(C5=CC=CN=C5)=N4)=C3)=CC(C(F)(F)F)=C2)C=C1")
>>> fp = os.path.join("path", "to", "mol.pdb")
>>> AllChem.rdmolfiles.MolToPDBFile(mol, fp)

And I can confirm by inspecting the file that the molecule has been exported correctly.

Any idea what might be going on? Am I missing a specific option in WL?

Thanks in advance.

  • $\begingroup$ ExportString[Molecule["CC1=CC(C2=CC(CC(=O)C3=CC=C(C)C(CC4=NC=CC(C5=CC=CN=C5)=N4)=C3)=CC(C(F)(F)F)=C2)C=C1", IncludeHydrogens -> True], "PDB"] seems to work OK. $\endgroup$ – J. M.'s ennui Jan 29 at 1:47
  • $\begingroup$ @J.M. you are correct! But this is so strange. I have the Molecule already, which won't export, but will when I do Molecule[MoleculeValue[mol, "CanonicalSMILES"], IncludeHydrogens -> All]. $\endgroup$ – Shredderroy Jan 29 at 1:53
  • $\begingroup$ @J.M.'sennui I will accept your comment as an answer if you post it. The solution is working for me. $\endgroup$ – Shredderroy Jan 29 at 2:44
  • 3
    $\begingroup$ I also don't reproduce the result from the WL code here, I get a PDB file string just fine. If you have a particular Molecule expression that doesn't export to PDB, you can file a bug report and attach a notebook with the problem molecule. $\endgroup$ – Jason B. Jan 29 at 2:47
  • $\begingroup$ In MMA 12.0 (Win10-64) the export command fails with a clearly bug-smelling "Export::type: RuleDelayed cannot be exported to the PDB format.". This looks like something went wrong inside. However, the same code works fine on MMA 12.2 (cloud version). I assume WRI fixed whatever bug they had in their internal code. $\endgroup$ – MarcoB Jan 29 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.