This example is based on Sun's Java applet "Molecule Viewer." (See below for a description of the implementation of this example.) There is another page available showing a part of a DNA molecule. |
I have no idea what this is. I just found it by searching for some nice XYZ files in the "The WWW Chemical Structures Database". |
The applet parameter POINT_EDGE_COLOR was set to a dark gray (#404040) in order to indicate edges of points representing carbon atoms.
This example also demonstrates stereo graphics with LiveGraphics3D. Actually all LiveGraphics3D applets (since version -1.60) can show stereo graphics: just move the mouse into the picture and press the "s" key. The "s" key also toggles between stereo pictures for diverge fusing (left picture for left eye, right picture for right eye) and cross fusing (left picture for right eye and vice versa).
In order to create these graphics, I wrote a simple converter from the XYZ format to the Graphics3D format within Mathematica:
$XYZTypes={{"H", 1.25, 0.32, RGBColor[1., 1., 1.]}, {"LI", 1.86, 1.23, RGBColor[0.698, 0.1333, 0.1333]}, {"B", 0.8, 0.82, RGBColor[0., 1., 0.]}, {"C", 1.65, 0.77, RGBColor[0.4392, 0.502, 0.5647]}, {"N", 1.5, 0.75, RGBColor[0., 0.749, 1.]}, {"O", 1.35, 0.73, RGBColor[1., 0., 0.]}, {"F", 1.4, 0.72, RGBColor[0.8549, 0.6471, 0.1255]}, {"NA", 1.12, 1.54, RGBColor[0., 0., 1.]}, {"MG", 0.87, 1.36, RGBColor[0.1333, 0.5451, 0.1333]}, {"AL", 1.7, 1.5, RGBColor[0.7529, 0.7529, 0.7529]}, {"SI", 1.93, 1.16, RGBColor[0., 0., 1.]}, {"P", 1.75, 1.06, RGBColor[1., 0.5, 0.]}, {"S", 1.85, 1.02, RGBColor[1., 1., 0.]}, {"CL", 1.8, 0.99, RGBColor[0., 1., 0.]}, {"K", 1.44, 2.03, RGBColor[1., 0.0784, 0.5765]}, {"CA", 1.18, 1.74, RGBColor[0.7529, 0.7529, 0.7529]}, {"SC", 1.37, 1.44, RGBColor[0.7529, 0.7529, 0.7529]}, {"TI", 1.37, 1.32, RGBColor[0., 1., 0.]}, {"V", 1.37, 1.22, RGBColor[0.7529, 0.7529, 0.7529]}, {"CR", 1.37, 1.18, RGBColor[0., 0., 1.]}, {"FE", 0.9, 1.17, RGBColor[1., 0.5, 0.]}, {"CO", 0.88, 1.16, RGBColor[0.5, 0.1647, 0.1647]}, {"NI", 0.69, 1.15, RGBColor[0.5, 0.1647, 0.1647]}, {"CU", 0.72, 1.17, RGBColor[0.5, 0.1647, 0.1647]}, {"ZN", 0.74, 1.25, RGBColor[0.5, 0.1647, 0.1647]}, {"GA", 1.37, 1.26, RGBColor[1., 0.7529, 0.7961]}, {"AS", 1.5, 1.6, RGBColor[1., 1., 0.]}, {"BR", 1.95, 1.14, RGBColor[0.5, 0.1647, 0.1647]}, {"RB", 1.58, 2.16, RGBColor[0.5, 0.1647, 0.1647]}, {"Y", 1.54, 1.805, RGBColor[1., 0.7529, 0.7961]}, {"ZR", 1.52, 1.675, RGBColor[1., 0.8431, 0.]}, {"NB", 1.5, 1.45, RGBColor[0., 0., 1.]}, {"PD", 1.3, 1.28, RGBColor[0., 1., 0.]}, {"AG", 1.27, 1.34, RGBColor[0.7529, 0.7529, 0.7529]}, {"CD", 1.15, 1.42, RGBColor[0.6784, 0.8471, 0.902]}, {"IN", 1.05, 1.48, RGBColor[0.6784, 0.8471, 0.902]}, {"SN", 1., 1.5, RGBColor[0.7529, 0.7529, 0.7529]}, {"I", 2.15, 1.33, RGBColor[0.6275, 0.1255, 0.9412]}, {"CS", 1.84, 2.35, RGBColor[0.5, 0.1647, 0.1647]}, {"BA", 1.655, 1.86, RGBColor[1., 1., 0.]}, {"LA", 1.47, 1.37, RGBColor[0.6784, 0.8471, 0.902]}, {"HF", 1.5, 1.6, RGBColor[1., 0.5, 0.]}, {"W", 1.55, 1.5, RGBColor[0., 1., 0.]}, {"PT", 1.3, 1.28, RGBColor[1., 0.7529, 0.7961]}, {"AU", 1.37, 1.34, RGBColor[0.8549, 0.6471, 0.1255]}, {"HG", 1.45, 1.39, RGBColor[1., 0., 0.]}, {"HE", 1.2, 0.31, RGBColor[1., 0.7529, 0.7961]}, {"U", 1.5, 1.4, RGBColor[0., 0., 1.]}, {"?", 1., 1., RGBColor[1., 0.0784, 0.5765]}}; ParseXYZRow[row_String,radius_]:= Module[{stream=StringToStream[row],first,position,result={}}, first=Read[stream,Word];position=Position[$XYZTypes,first]; If[position!={}, result={{PointSize[ 2*radius*$XYZTypes[[position[[1,1]],3]]],$XYZTypes[[ position[[1,1]],4]], Point[{Read[stream,Number],Read[stream,Number], Read[stream,Number]}]}}];Close[stream];result] ReadXYZ[name_,radiusScaling_:1]:= Module[{result={},rows,diagonal}, rows=ReadList[name,Record,RecordSeparators->{"\n","\r"}]; result=Flatten[Map[ParseXYZRow[#,radiusScaling]&,rows]]; diagonal=Sqrt[ Apply[Plus, Map[(1.05*(#[[2]]-#[[1]]))^2&, Map[Part[#,{1,-1}]&, Map[Sort, Transpose[ Cases[result,Point[_],Infinity]/.Point[{x_,y_,z_}]:> N[{x,y,z}]]]]]]]; result=result/.PointSize[s_]:>PointSize[s /diagonal]; Graphics3D[{result},SphericalRegion->True,PlotRange->All,Boxed->False, Background->GrayLevel[0]]]
With these definitions a XYZ file "name.xyz" can be converted to a Graphics3D object called g by
g = ReadXYZ["name.xyz"]
or multiplying all radii with factor
g = ReadXYZ["name.xyz", factor]
The graphics can be viewed with Show[g] within Mathematica.
The procedure to display the Graphics3D object with LiveGraphics3D
is explained in the documentation.