Re: Chem PDB files, Export and Manipulation
- To: mathgroup at smc.vnet.net
- Subject: [mg95457] Re: Chem PDB files, Export and Manipulation
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Mon, 19 Jan 2009 02:57:19 -0500 (EST)
- References: <gksbn6$dqp$1@smc.vnet.net>
Hi, > I would like to use Mathematica 7.0's ability to import pdb files and > other (supported) chemistry related files into a Graphics3D object, to > be able to position and manipulate the resulting molecules and their > coordinates relative to other objects (Polygons, GraphicsComplexes, > etc.). > > How can this be done? Is it possible to manipulate a single atom's > position within Mathematica's objects, or does it need to be specified > in the pdb file beforehand? It is definitely possible, but for typical content of these files it might be somewhat difficult to locate the graphics primitives that you need to manipulate. This is not only because there might be plenty of them but also because the imported graphics make use of GraphicsComplex, which is reasonable and a good choice but makes the location probably somewhat more complex. With good knowledge and understanding of Mathematica basics (especially pattern matching I would guess) and some experience it should be possible, but I don't know of any easy klick and point way to do what you want for 3d graphics with many objects and GraphicsComplexes. > When imported into Mathematica, are pdb files scalable vectors, or > bitmaps? It seems that the resolution of the collective atoms > deteriorates considerably once you expand the original image (within > Mathematica, of course). Is it possible to export the resulting 3D > image to a vector image? Not being an expert for this kind of data I am left with the example data, which seem to be imported correctly as Mathematica graphic objects, which means they are mathematica expressions representing vector graphics. If you choose a vector image format as output Mathematica will usually export vector data and not converting to pixels, AFAIK. You might have seen the behavior you describe when looking at the documentation, in which most large graphics are converted to pixel formats to make the documentation more compact. If you reevaluate everything, the graphics should be rendering nice also when expanding the image, you can then also rotate and zoom... > The section dealing with Chemistry/Biology objects in the Mathematica > help is not very clear (understatement) on how to include and > manipulate the resulting molecules within other graphical objects. that is a typical problem with the help: it probably suggests that you are familiar with the mathematicas 'paradigms', especially this one: 'everything is an expression'. When understanding that the molecule-data is imported as a 3d-Graphics-object and that, of course :-), is an expression, you will understand that there is no need to handle or explain these in any special way. You can just use all the regular functions to manipulate expressions of any kind. To see them in 'expression format' you can look at them with InputForm or FullForm. Admittedly that is not much help for those who are not so familiar with all the details of Mathematica, so some examples in the documentation would be a big help, of course... > If anyone knows anything about this, I would appreciate your help! not too much, but I hope it still is of some help. I have included some code which shows how you can create an interface to interactively manipulate the position of one atom in one of the examples provided with mathematica, not a very realistic use case but probably a starting point.... albert Import something from the example data: pdb100d=Import["ExampleData/100d.pdb",ImageSize->300] There are 23 GraphicsComplexes in the graphics3d: Cases[pdb100d,GraphicsComplex[___],Infinity]//Length You can extract just the first of them: gc1=Cases[pdb100d,GraphicsComplex[___],Infinity][[1]]; and show only it alone: Graphics3D[gc1] Combining these with a manipulate you can find which of them is what is of interest to you. To do this, I extract the plotrange of the total view: prange=AbsoluteOptions[Graphics3D[Cases[pdb100d,GraphicsComplex[___],Infinity]],PlotRange] ... and use that to fix the PlotRange: Manipulate[ Graphics3D[Cases[pdb100d,GraphicsComplex[___],Infinity][[k]],prange[[1]],PlotLabel->k], {k,1,Length[Cases[pdb100d,GraphicsComplex[___],Infinity]],1} ] In the following, we would like to manipulate one of the atoms in the chain represented by graphics complex number 23: Graphics3D[Cases[pdb100d,GraphicsComplex[___],Infinity][[23]]] These are the coordinates of the first point in the GraphicsComplex, which happens to be the coordinate of the first atom of this chain: Cases[pdb100d,GraphicsComplex[___],Infinity][[23]][[1,1]] Making use of all the above, this will give you an interface to manipulate the coordinates of that first atom: With[{defaults=Cases[pdb100d,GraphicsComplex[___],Infinity][[23]][[1,1]]}, Manipulate[ Graphics3D[{ Delete[Cases[pdb100d,GraphicsComplex[___],Infinity],23], Dynamic[ReplacePart[Cases[pdb100d,GraphicsComplex[___],Infinity][[23]],{1,1}->{x,y,z}]] }], {{x,defaults[[1]]},defaults[[1]]-1000,defaults[[1]]+1000}, {{y,defaults[[2]]},defaults[[2]]-1000,defaults[[2]]+1000}, {{z,defaults[[3]]},defaults[[3]]-1000,defaults[[3]]+1000} ] ] Some notes: 1) the Dynamic is only included for performance reasons -- but makes a big difference :-), 2) manipulating the coordinates of a graphics complex instead of coordinates of single graphics primitives has the advantage that the chain stays intact: the connection to the next atom is automatically changed, too. Of course that is not always what you want, so sometimes you would even need to pull some of the graphic primitives out of the graphics complex.