{"id":762,"date":"2016-01-26T16:03:05","date_gmt":"2016-01-26T21:03:05","guid":{"rendered":"https:\/\/bmcresearch.utm.utoronto.ca\/sciencevislab\/?p=762"},"modified":"2016-01-26T16:07:58","modified_gmt":"2016-01-26T21:07:58","slug":"generating-geometry-for-ball-and-stick-molecules","status":"publish","type":"post","link":"https:\/\/sciencevis.ca\/index.php\/2016\/01\/26\/generating-geometry-for-ball-and-stick-molecules\/","title":{"rendered":"Generating geometry for ball and stick molecules"},"content":{"rendered":"[vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/1&#8243;]<div class=\"img-with-aniamtion-wrap center\" data-max-width=\"100%\" data-border-radius=\"\"><div class=\"inner\"><a href=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_Siderocalin.jpg\" class=\"pp center\"><img loading=\"lazy\" decoding=\"async\" data-shadow=\"none\" data-shadow-direction=\"middle\" class=\"img-with-animation skip-lazy \" data-delay=\"0\" height=\"1080\" width=\"1920\"  data-animation=\"fade-in\" src=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_Siderocalin.jpg\" srcset=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_Siderocalin.jpg 1920w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_Siderocalin-300x169.jpg 300w\" sizes=\"auto, 100vw\" alt=\"\" \/><\/a><\/div><\/div>[\/vc_column][\/vc_row][vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;2\/3&#8243;][vc_column_text]For an upcoming <a href=\"https:\/\/bmcresearch.utm.utoronto.ca\/sciencevislab\/index.php\/portfolio\/molecular-visualization-principles\/\">Molecular Visualization Principle<\/a>, I decided to\u00a0include a small molecule, which is something new for the series.<\/p>\n<p>Small molecules typically\u00a0use CPK space-filling or ball and stick representations, because surface meshes aren&#8217;t very informative. It&#8217;s more interesting to see structures like benzene rings\u00a0when\u00a0present. In order to bring the associated small molecule in with the protein structure I was importing using <a href=\"https:\/\/clarafi.com\/tools\/mmaya\/\" target=\"_blank\">Molecular Maya<\/a>, it was necessary to ensure that the HETATMs option was checked in the import options.<\/p>\n<p>For the protein\u00a0component, I kept the established simplified surface mesh used in the series so far. I decided on a modified ball and stick representation with pinched bonds, which Molecular Maya is capable of generating. The requirements of the animation and rendering process were such that I really needed regular geometry for the atoms and bonds, respectively\u00a0balls and sticks.\u00a0However, in the version of the software I was using,\u00a0these structures were built with spherical particles and\u00a0geometry instanced to particles. Maya unfortunately doesn&#8217;t have a particle instance to\u00a0regular geometry conversion tool, so I was left to find my own workaround for this task. I&#8217;m confident that in the future, either or both of Autodesk Maya and Molecular Maya will have the\u00a0capability of automatically performing the following, but\u00a0at the time, this process was not implemented in the software.<\/p>\n<p>First, I needed access to the underlying nodes in the mMaya hierarchy. I did this by selecting the mMaya node prefixed with pdbMolStruc_ and running the below code.<\/p>\n<p><em>Note: this\u00a0webpage has likely converted the regular quote marks to &#8220;smart quotes&#8221;, which will need to be replaced in\u00a0your script editor with &#8220;straight\u00a0quotes&#8221;.<\/em>[\/vc_column_text][vc_column_text]<!--more-->[\/vc_column_text]<div class=\"divider-wrap\" data-alignment=\"default\"><div style=\"height: 25px;\" class=\"divider\"><\/div><\/div>[vc_column_text el_class=&#8221;codeBlock&#8221;]\/\/Reveal mMaya nodes<br \/>\nstring $pdbMolStrucNode[] = `ls -sl`;<br \/>\nlockNode -lock 0 $pdbMolStrucNode[0];<br \/>\nsetAttr -lock 0 ($pdbMolStrucNode[0] + &#8220;.blackBox&#8221;);<br \/>\nsetAttr ($pdbMolStrucNode[0] + &#8220;.blackBox&#8221;) 0;[\/vc_column_text][\/vc_column][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/3&#8243;]<div class=\"img-with-aniamtion-wrap center\" data-max-width=\"100%\" data-border-radius=\"\"><div class=\"inner\"><img loading=\"lazy\" decoding=\"async\" data-shadow=\"none\" data-shadow-direction=\"middle\" class=\"img-with-animation skip-lazy \" data-delay=\"0\" height=\"396\" width=\"433\"  data-animation=\"fade-in\" src=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/mMaya_HETATMs.png\" srcset=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/mMaya_HETATMs.png 433w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/mMaya_HETATMs-300x274.png 300w\" sizes=\"auto, 100vw\" alt=\"\" \/><\/div><\/div><div class=\"divider-wrap\" data-alignment=\"default\"><div style=\"height: 25px;\" class=\"divider\"><\/div><\/div><div class=\"img-with-aniamtion-wrap center\" data-max-width=\"100%\" data-border-radius=\"\"><div class=\"inner\"><img loading=\"lazy\" decoding=\"async\" data-shadow=\"none\" data-shadow-direction=\"middle\" class=\"img-with-animation skip-lazy \" data-delay=\"0\" height=\"521\" width=\"594\"  data-animation=\"fade-in\" src=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Ball_and_stick_01.png\" srcset=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Ball_and_stick_01.png 594w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Ball_and_stick_01-300x263.png 300w\" sizes=\"auto, 100vw\" alt=\"\" \/><\/div><\/div>[\/vc_column][\/vc_row][vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/1&#8243;][vc_column_text]After revealing\u00a0the\u00a0particle nodes, I\u00a0made a simple sphere and\u00a0also copied the pinch bond geometry as\u00a0a template for the sticks\u00a0to be created. Then I ran the following two scripts, which created the geometry for me. The first one creates the atoms. You\u00a0would\u00a0have to change the named nodes (e.g. HET_EB4_0_particle) to the name of the particle node in your scene, and name the template sphere &#8220;sphereAtom&#8221; or change the code accordingly. Again, change the &#8220;smart quotes&#8221; to &#8220;straight quotes&#8221;. I didn&#8217;t really write the script to be a robust resource so much as a quick fix for myself.[\/vc_column_text][\/vc_column][\/vc_row][vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/2&#8243;]<div class=\"img-with-aniamtion-wrap center\" data-max-width=\"100%\" data-border-radius=\"\"><div class=\"inner\"><img loading=\"lazy\" decoding=\"async\" data-shadow=\"none\" data-shadow-direction=\"middle\" class=\"img-with-animation skip-lazy \" data-delay=\"0\" height=\"554\" width=\"607\"  data-animation=\"fade-in\" src=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/EB_spheres.png\" srcset=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/EB_spheres.png 607w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/EB_spheres-300x274.png 300w\" sizes=\"auto, 100vw\" alt=\"\" \/><\/div><\/div>[\/vc_column][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/2&#8243;][vc_column_text el_class=&#8221;codeBlock&#8221;]\/\/Ensure the atomSphere has a radius of the &#8220;ball and stick vWaals scale&#8221; to start<\/p>\n<p>string $particleNode = &#8220;HET_EB4_0_particle&#8221;;<br \/>\nstring $atomGrp = `group -em -n &#8220;atomGeoGrp&#8221;`; \/\/new empty group for atom geo<\/p>\n<p>int $numParticles = `particle -q -ct $particleNode`;<\/p>\n<p>for ($i = 0; $i &lt; $numParticles; $i++){<\/p>\n<p style=\"padding-left: 30px;\">vector $atomPos = `particle -attribute position -id $i -q $particleNode`;<br \/>\nfloat $atomRadius[] = `particle -attribute radiusPP -id $i -q $particleNode`;<br \/>\nstring $newAtom[] = `instance &#8220;atomSphere&#8221;`; \/\/create new instance of original atom geo<br \/>\nfloat $atomPosX = $atomPos.x;<br \/>\nfloat $atomPosY = $atomPos.y;<br \/>\nfloat $atomPosZ = $atomPos.z;<br \/>\nmove $atomPosX $atomPosY $atomPosZ $newAtom[0];<br \/>\nscale -r $atomRadius[0] $atomRadius[0] $atomRadius[0] $newAtom[0];<\/p>\n<p style=\"padding-left: 30px;\">string $newObj = `rename $newAtom[0] (&#8220;atomSphere_&#8221; + $i)`;<br \/>\nparent $newObj $atomGrp; \/\/add to the atom group<\/p>\n<p>}[\/vc_column_text][\/vc_column][\/vc_row][vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/1&#8243;][vc_column_text]This second script creates the bonds. I had to do some tricky\u00a0stuff (not that tricky) to get the aim attribute\u00a0that the particle bonds were using into rotation for the geometry. Again, change the node name at the top, the bond template object\u00a0&#8220;new_geoBondPrim&#8221; and make sure there aren&#8217;t any &#8220;smart quotes&#8221;, if you do decide to use this on your own scene.[\/vc_column_text][\/vc_column][\/vc_row][vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;2\/3&#8243;][vc_column_text el_class=&#8221;codeBlock&#8221;]string $particleBondNode = &#8220;HET_EB4_0_particleBonds&#8221;; \/\/state the name of the mMaya node<br \/>\ngroup -em -n &#8220;bondGeoGrp&#8221;; \/\/new empty group for bond geo<\/p>\n<p>int $numParticles = `particle -q -ct $particleBondNode`; \/\/get number of particles<\/p>\n<p>for ($i = 0; $i &lt; $numParticles; $i++){<\/p>\n<p style=\"padding-left: 30px;\">vector $bondPos = `particle -attribute bondPos -id $i -q $particleBondNode`;<br \/>\nvector $bondScaler = `particle -attribute bondScaler -id $i -q $particleBondNode`;<br \/>\nvector $vel = `particle -attribute velocity -id $i -q $particleBondNode`;<\/p>\n<p style=\"padding-left: 30px;\">string $newBond[] = `instance &#8220;new_geoBondPrim&#8221;`; \/\/create new instance of original bond geo<\/p>\n<p style=\"padding-left: 30px;\">float $bondPosX = $bondPos.x;<br \/>\nfloat $bondPosY = $bondPos.y;<br \/>\nfloat $bondPosZ = $bondPos.z;<br \/>\nmove $bondPosX $bondPosY $bondPosZ $newBond[0];<br \/>\nfloat $bondScaleX = $bondScaler.x;<br \/>\nfloat $bondScaleY = $bondScaler.y;<br \/>\nfloat $bondScaleZ = $bondScaler.z;<br \/>\nscale -r $bondScaleX $bondScaleY $bondScaleZ $newBond[0];<\/p>\n<p style=\"padding-left: 30px;\">float $bondAimX = $vel.x;<br \/>\nfloat $bondAimY = $vel.y;<br \/>\nfloat $bondAimZ = $vel.z;<br \/>\nvector $bondRot = `angleBetween -er -v1 1 0 0 -v2 $bondAimX $bondAimY $bondAimZ`; \/\/convert aim vector to rotation<br \/>\n$bondRotX = $bondRot.x;<br \/>\n$bondRotY = $bondRot.y;<br \/>\n$bondRotZ = $bondRot.z;<br \/>\nrotate $bondRotX $bondRotY $bondRotZ $newBond[0];<br \/>\nstring $newObj = `rename $newBond[0] (&#8220;geoBond_&#8221; + $i)`;<br \/>\nparent $newObj &#8220;bondGeoGrp&#8221;; \/\/add to the bond group<\/p>\n<p>}[\/vc_column_text][\/vc_column][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/3&#8243;]<div class=\"img-with-aniamtion-wrap center\" data-max-width=\"100%\" data-border-radius=\"\"><div class=\"inner\"><img loading=\"lazy\" decoding=\"async\" data-shadow=\"none\" data-shadow-direction=\"middle\" class=\"img-with-animation skip-lazy \" data-delay=\"0\" height=\"524\" width=\"587\"  data-animation=\"fade-in\" src=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/EB_sticks.png\" srcset=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/EB_sticks.png 587w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/EB_sticks-300x268.png 300w\" sizes=\"auto, 100vw\" alt=\"\" \/><\/div><\/div><div class=\"divider-wrap\" data-alignment=\"default\"><div style=\"height: 25px;\" class=\"divider\"><\/div><\/div><div class=\"img-with-aniamtion-wrap center\" data-max-width=\"100%\" data-border-radius=\"\"><div class=\"inner\"><img loading=\"lazy\" decoding=\"async\" data-shadow=\"none\" data-shadow-direction=\"middle\" class=\"img-with-animation skip-lazy \" data-delay=\"0\" height=\"440\" width=\"440\"  data-animation=\"fade-in\" src=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_SID_Test_EB.png\" srcset=\"https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_SID_Test_EB.png 440w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_SID_Test_EB-150x150.png 150w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_SID_Test_EB-300x300.png 300w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_SID_Test_EB-50x50.png 50w, https:\/\/sciencevis.ca\/wp-content\/media\/2016\/01\/Prnc12_SID_Test_EB-100x100.png 100w\" sizes=\"auto, 100vw\" alt=\"\" \/><\/div><\/div>[\/vc_column][\/vc_row][vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/1&#8243;][vc_column_text]And\u00a0that gave me the geometry I needed for my animation. In this particular case I wanted to give everything the same shader, not using atom color coding; but if that was that case, you would have to keep track of which atoms were of what type.\u00a0A future challenge![\/vc_column_text][\/vc_column][\/vc_row]\n","protected":false},"excerpt":{"rendered":"<p>[vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;1\/1&#8243;][\/vc_column][\/vc_row][vc_row type=&#8221;in_container&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_position=&#8221;all&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; width=&#8221;2\/3&#8243;][vc_column_text]For an upcoming Molecular Visualization Principle, I decided to\u00a0include a small molecule,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,26],"tags":[],"class_list":{"0":"post-762","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-molecular","7":"category-process"},"_links":{"self":[{"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/posts\/762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/comments?post=762"}],"version-history":[{"count":22,"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/posts\/762\/revisions"}],"predecessor-version":[{"id":790,"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/posts\/762\/revisions\/790"}],"wp:attachment":[{"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/media?parent=762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/categories?post=762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sciencevis.ca\/index.php\/wp-json\/wp\/v2\/tags?post=762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}