Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: most ChemicalData molecule plots missing? [solved]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96740] Re: [mg96163] most ChemicalData molecule plots missing? [solved]
  • From: Mitch Murphy <mitch at lemma.ca>
  • Date: Mon, 23 Feb 2009 05:03:18 -0500 (EST)
  • References: <499F3178.3080600@wolfram.com>

On Feb 07, 2009, at 03:52, Mitch Murphy wrote:

> i'm getting a lot of missing molecule plots for even the simplest and
> most common molecules in ChemicalData[]...
>
> most hydrocarbons are also missing.
>
> is this normal, or could there be something wrong with my mathematica
> install or a cached curated data problem?
>
> i was expecting molecule plots to be automatically generated from the
> chemical formulas, but looks like it's not. i guess its down to
> manually using graphics3d, spheres, and cylinders ...
>


i wrote the following ElementPlot3D and MoleculePlot3D functions which  
automatically generate the molecule plot based on

	ElementData[atom, "AtomicRadius"]
	ElementData[atom, "Abbreviation"]
	ChemicalData[chem, "AtomPositions"]
    	ChemicalData[chem, "VertexCoordinates"]
	ChemicalData[chem, "VertexTypes"]
  	ChemicalData[chem, "EdgeRules"]

my code uses VertexCoordinates if AtomPositions is missing, but does  
not handle both missing. another potential improvement would be to  
have double/triple edge rules where applicable (all bonds are drawn as  
a single tube in my code).

cheers,
Mitch

-------------------------


ElementPlot3D[atom_, {x_: 0, y_: 0}] := Module[{radius},

  	radius = ElementData[atom, "AtomicRadius"];

  	{ElementData[atom, "IconColor"], Sphere[{x, y, 0}, .4 radius],
   		Black,
   Style[Text[ElementData[atom, "Abbreviation"], {x, y, .4 radius}],
    FontSize -> 12]}

  ]

ElementPlot3D[atom_, {x_: 0, y_: 0, z_: 0}] := Module[{radius},
  	radius = ElementData[atom, "AtomicRadius"];
  	{Darker@ElementData[atom, "IconColor"], Sphere[{x, y, z}, .5 radius]}
  ]

MoleculePlot3D[chem_,
  opts : OptionsPattern[{ImageSize -> 200, Frame -> True}]] := Module[
  	{atomCoordinates, atomTypes, atomColors, atomGraphics, edgeRules,
   edgeGraphics},

  	atomCoordinates = ChemicalData[chem, "AtomPositions"]
    		/. _Missing -> ChemicalData[chem, "VertexCoordinates"];

  	atomTypes = ChemicalData[chem, "VertexTypes"];
  	edgeRules = ChemicalData[chem, "EdgeRules"];

  	edgeGraphics = Table[Tube[{
      		If[Length@First@atomCoordinates > 2,
       atomCoordinates[[edgeRules[[i, 1]]]],
       			Append[atomCoordinates[[edgeRules[[i, 1]]]], 0]],
      		If[Length@First@atomCoordinates > 2,
       atomCoordinates[[edgeRules[[i, 2]]]],
       			Append[atomCoordinates[[edgeRules[[i, 2]]]], 0]]
      		}, 4,
     VertexColors ->
      Evaluate[
       ElementData[#, "IconColor"] & /@
        			
        atomTypes[[{edgeRules[[i, 1]], edgeRules[[i, 2]]}]]]],
    	{i, Length@edgeRules}];
  	
  	atomGraphics = Table[ElementPlot3D[atomTypes[[i]],  
atomCoordinates[[i]]],
    		{i, Length@atomCoordinates}];

  	Graphics3D[{Thick, edgeGraphics, atomGraphics}, Boxed -> False,
   ViewPoint -> Top,
   		Background -> GrayLevel@.9, ImagePadding -> 20, ImageSize ->  
{400, 280},
   Lighting -> "Neutral"]

  ]

GraphicsRow[{MoleculePlot3D@"CarbonDioxide", MoleculePlot3D@"Ethanol"},
ImageSize -> 500]




  • Prev by Date: Re: follow up on pde nonlinear modeling
  • Next by Date: Re: Re: Re: Optimization problem
  • Previous by thread: Re: Error using Manpulate that is NOT obvious (to me)
  • Next by thread: Re: most ChemicalData molecule plots missing? [solved]