5
$\begingroup$

I'm trying to resolve a problem with the new Molecule[] functionality in Mathematica 12.

The "AtomDiagramCoordinates" property returns 2D coordinates of the molecular graph. These coordinates can be used to overlay graphics on the molecule. However, it appears that sometimes the coordinates need an extra minus sign to be consistent with the 2D-diagram created by MoleculePlot[]:

atomCoordinatesTest[m_Molecule, sign_: + 1] :=
 Show[
  MoleculePlot[m],
  Graphics@Disk[
    sign*m["AtomDiagramCoordinates"][[3]],
    0.3]]

exampleMolecules = {Molecule["Azulene"], Molecule["Phenanthrene"]};
atomCoordinatesTest[#, +1] & /@ exampleMolecules (*no sign flip needed for phenanthrene*)

atomCoordinatesTest[#, -1] & /@ exampleMolecules (*azulene needs a sign flip*)

Picture drawing a circle on atom 3

This is all in $Version "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)"

Am I missing something here, or is this a bug?

$\endgroup$
6
$\begingroup$

There is an inconsistency here, regarding how Molecule and MoleculePlot handle hydrogens.

By default, MoleculePlot will give a 2D graphics with most hydrogens not shown explicitly. It will do this regardless of whether the molecule expression has explicit hydrogens. But Molecule will always return a list of "AtomDiagramCoordinates" with a coordinate for every explicit atom.

And for azulene, the automatic layout is different depending on whether hydrogens are show:

MoleculePlot[Molecule["azulene"], IncludeHydrogens -> #] & /@ {True, False}

enter image description here

which is why the placement is off. For your example, if you create the molecules with all hydrogens implicit, then the diagram coordinates will match what is being plotted:

exampleMolecules = {Molecule["Azulene", IncludeHydrogens -> False], 
   Molecule["Phenanthrene", IncludeHydrogens -> False]};
atomCoordinatesTest[#, +1] & /@ exampleMolecules 

enter image description here

I certainly consider this behavior buggy, but I'm not certain what is the right thing to do. I am leaning towards making the default behavior for MoleculePlot to display the hydrogens if they are present in the molecule, and if you want to have explicit hydrogens in the molecule but not the 2D plot then you need to pass an option to MoleculePlot. The functions are still experimental, so this kind of design change is possible given feedback from users.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Wow! Thanks for the tip here. I can confirm that your solution works, and agree that the current implementation defaults seems a bit unpolished. $\endgroup$ – Joshua Schrier Oct 11 '19 at 15:35
  • $\begingroup$ I'm interested in user feedback about how hydrogens should be handled by default. I made a post on community if you have any thoughts on the matter. $\endgroup$ – Jason B. Oct 11 '19 at 17:00
  • $\begingroup$ As a (non-organic) chemist, IncludeHyrdogens ->False seems like the right default, with consistent behavior in both Molecule[] and MoleculePlot[] $\endgroup$ – Joshua Schrier Oct 11 '19 at 18:25
  • $\begingroup$ As someone who works with stuff like H5+ I'd say I'm partial to IncludeHydrogens->True :) But I never work with a 2D representation anyway $\endgroup$ – b3m2a1 Oct 11 '19 at 19:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.