Blender for Scientists - How to Make ANY Molecule in Blender

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's dive right in today i'm going to be showing you how to make any molecule you want in blender now there is one exception and that is crystals i'm going to be pursuing crystal structures in a future tutorial and that's coming shortly today we're not going to actually be starting in blender we're going to be starting with a program called avogadro and also another program called open babble so go to your browser of choice come to avogadro.cc follow the links to download this is a free platform so don't worry about any cost concerns and similarly for open babble this is the web page here follow the download links download install both programs when you're done you can come over to avogadro and avogadro has a relatively intuitive interface when you open it up you're going to have a number of tools the main ones that we care about are draw and optimize so if you wanted to you can set the element that you are drawing carbon the hydrogen nitrogen oxygen sulfur etc the type of bond all that and you can just draw out click and create any molecule you want and if you draw wildly off like this don't worry about that because all you have to do is click this little e for auto optimization hit start and it'll very quickly optimize and you just wait until this energy level gets to a minimum or until it's at a point where you're happy with it anything like this would be sort of okay so i'm just going to stop this here now the reality of avogadro is that it is kind of curiously powerful and not because of the fact that you can draw not because of the fact that it's free very simply because of the fact that it has an import feature and it's actually import by chemical name and you can essentially write in all kinds of things and it will bring up the molecular structure for you so i'm going to run through a few examples here to show some of the flexibility so let's start with something very common namely ibuprofen and if we wait a few seconds you can see there's ibuprofen right away and this is the actual structure now you'll notice that i've moved to this little cursor here and now with left click i can sort of rotate around with right click i can pan with middle mouse i can zoom in or out and that's all very simple let's choose something perhaps a little bit more obscure for some viewers i.e import touch by chemical name and we'll go with boron subthalasine chloride we wait and there it is so there's a very good range here now the molecule that i want to use is ciprofloxacin and we're going to do that for a few reasons but there are a few points that i want to address first one is that if you try and enter a name and it doesn't work maybe because you mistyped it or something like that then you can usually figure that out by just trying to move around and if you actually see this cursor appear but there's no molecule just try it again so either close avogadro try it again or try entering the name again it is sometimes a little bit touchy but it usually will work if you've got the name right as with many chemistry related things there are usually other names for the compound as well so you may just want to try finding those names on wikipedia or a website such as sigma aldrich and trying an alternative name now let's go ahead and import ciprofloxacin so fetch by chemical name and we're going to go with ciprofloxacin and there we go this is ciprofloxacin the reason that i want to use this one specifically is that it's going to touch a number of things so normally to get this file and import it into blender you would go to file save as and you would save as this type of format pdb and then you'd import that into blender we're not going to actually use pdb today and there's a very specific reason for that if you want to visualize one of these molecules in blender you will not be able to access double or triple bonds if you save to pdb straight from avogadro that's why we have open battle the other reason that we're using ciprofloxacin is that it's going to give us a few errors when we move to open babel that are something that i think it's good to be aware of if it's a troubleshooting problem that you're going to encounter so right away what we're going to do now is we've got our ciprofloxacin we're going to file save as and we're actually going to save as this format dot mole so you can see it's actually right above pdb and i'm just going to go ahead and throw this in a directory of making any molecule and we'll call this ciprofloxacin and save from there we're done with avogadro we're going to close it and we're going to come and open up open babble and this is essentially the interface we're going to be inputting a dot mol file which we get from avogadro and we're going to be exporting a pdb but this time it's going to have the information for double or triple bonds if you do not care about double or triple bonds or your molecule does not have those molecules save as pdb right from avogadro and skip this step but for those of you who do we're going to go ahead set the directory and you can see a number of tests that i've been working on here but we're going to go straight to here and we're going to call this again ciprofloxacin save as there we go and we're going to import the file that we want namely the ciprofloxacin.mole file that we just made and now we're going to throw on a few little steps the only one that really matters for getting the double and triple bonds is generate 3d coordinates so i'm going to click this box and i'm going to convert and this is why i chose ciprofloxacin because it's actually going to throw a few errors here so if you see this nan not a number that means that there's been a problem the problems usually arise from hydrogens and generally speaking when you're visualizing a lot of molecules you can usually get away with not showing hydrogens so i'm actually just going to select the box for delete hydrogens and then i'm going to convert it again this is going to overwrite the file but now you see we have a different problem and this is that it has generated these huge strings of numbers this is not a usable file if you try and import this to blender it never will so for whatever strange reason when this happens just uncheck generate 3d coordinates and then convert it again and now everything will work and it will have the 3d coordinates so you will get your double and triple bonds you won't get the hydrogens but everything is actually going to work again you should just start by going with generate 3d coordinates and converting and if you don't have a not a number problem or you don't see any ridiculously huge numbers your file is probably fine so we now have our pdb file and we're going to transition over and get started in blender we're now finally in blender and to start we're going to go to edit preferences add-ons and what we're looking for is an add-on called atomic blender and this is going to let you import these pdb or xyz files once that's installed go ahead close out we're going to delete the default cube and i'm going to come up to file import protein databank this will only be visible if you have atomic blender installed and then we're going to navigate to where that file is so making any molecule ciprofloxacin and this is where we're going to get into our default settings if you are going to be working with this sort of out of box stick with nurbs that's fine always in my opinion change the ball size to at least 0.5 the one size is comically ridiculous and for the options here we're going to start off with dupliverts which is the baseline but there are other options for skin and normal skin is something we'll touch at the very end it can give very neat effects and normal is something that while i actually like it a little bit more than dupliverts it does have some problems and so dupliverts is really the best way to go for this again we're going to check bonds if we have double and triple bonds we do i'd like to show them and we're going to drop the radius to 0.1 you can drop it higher or lower if you want after seeing the way it shows up from here go ahead and simply import and you can see this is what's been imported this entire collection everyone separated by atoms and we now have every atom contained and this is our molecule i'm going to take a second now to explain what's actually happening with the dupliverts and what duplivers essentially has done and what all the atoms are as well are they are instance objects so there's actually one object for all of these and they are being placed on a plane essentially and it's similar to a particle system but not quite so you can see if i come to the carbon atom and open this i have this object carbon ball now if i visualize this so it's actually hidden right now but if i unhide it you see this is the object and if i want to change all the carbon atoms at once i simply have to make this object visible and then i can change it so i could scale it up or down i could come to the materials tab and change it from here and this is a worthwhile thing to note because for many people this is going to be fine out of box right now you can see these little rectangles but they're not super important if i come into material preview or into rendered mode you notice that again the dividing lines that you see are now gone if that is not as smooth as you want then again very simply what you have to do is activate these cylinders for the specific bond in question so it'll be different for nitrogen and for carbon we're going to hide that ball and then we're simply going to grab this cylinder right click and shade smooth and now you can see all of the bonds connected to that are smooth if we look over here the nitrogen ones are not smooth so you'll have to go through for each individual type of atom and make the bond smooth if you were importing these files in a different way and there are other ways you can do it you won't get all the preset materials and that is something that i think is very nice just because it makes it easy to manipulate the whole scene one of the things that i will say before we get into the actual full complicated version of this is that if you're going to use this out of box in this form which is totally fine one thing that you may want to do is actually just create separate materials for the carbon parts or for the atom parts rather as opposed to the bonds so if you don't want your bonds and your atoms to have exactly the same material this is a great time to separate them you're going to have to do that through the mesh in the collection so again come to the mesh that you actually want and then you can change the material here if i wanted the atoms to be separate from the bonds i would simply hit this little three if you're wondering why it's three it's because these bonds actually have a full cylinder but the top and bottom of the cylinder are actually separate from the cylinder itself if that doesn't really make sense i'll show you what i mean here so this is the actual cylinder and then there is a cup that goes on top and bottom and those are separate so three objects will share the same material if you want to change them then simply click this little button it'll make each material its own and i'll show that right now with the carbon bonds so we'll go ahead we'll click the ball actually i want to change the ball first and now i'm going to click this it's its own material so if i wanted to i could change the carbon atom specifically to be black and i would actually still have the bonds be that same white as before one thing that is worth noting here is that if you are going to click this use nodes button it's going to reset the entire material and these are essentially the basic toggles that you would ever really need so if you're just going to try and keep your atoms and materials in a kind of either shiny or metallic smooth or rough space then these are all the toggles you'll need if you really want to get into other things like having some of your atoms be metallic or glass or whatever you are going to have to click use nodes but it is going to reset that completely to white so then i could change this however i want with all the full controls of the node network and that's fine one thing that i forgot to mention is that if you want to change the relative sizes of the atoms at any point you should do that before you apply any of the steps that are coming after this so from here i'm going to talk about merging all of these atoms and bonds into a single object that you can then manipulate if you are not happy with the relative sizes you can do it after all the transformations but it's much easier to do it now simply grab the bond that you want or the atom that you want rather so in this case we're looking at carbon you're going to open its relative collection and then make the carbon ball or whatever atom it is visible once you have this one which all of these reflect then scale it and all the rest will adjust automatically that is the easiest way to do this make sure you're going to do it at this stage if you're not happy if you're not happy with the actual bond sizes i strongly recommend just re-importing the model and then trying different bond radii until you find one that you're happy with because when i make both of these visible and grab them you can see if i try and scale i'm actually going to make all of the instancing planes visible then i would have to figure out how to scale them locally so that it's actually going to work without warping the aspect ratio i'd probably have to grab all the plane objects change types of coordinates and scale relative that it's really a giant nuisance just re-import the model with the correct bond radii and work from there so from here we're going to resume merging all of these into a single object that you can then work with in particle systems and modifiers so from here i'm going to get into a little bit of why i do not really like the dupli-verts approach and where you can go forward if you want to do more things with this now dupli-verts again as i mentioned are instance geometry so every point here every part of these little planes you can see every segment in the bonds is essentially there's a small plane there and then there are cylinders being matched to that point in space using coordinates from the file we got from avogadro or from openbabel now that's totally fine up until the point where you want to take multiple molecules and put them into places because then it can be a pain to have to duplicate this whole collection it's really frustrating if you want to use these as particles a lot of the covers that i see and a lot of the work that i see that uses molecules actually tends to spread them out in multiple places and i personally like to use particle systems for that and i feel like it consolidates all the objects in one space so if you're happy with the molecule like this and you just want to do customizations stop here change the materials set up the render you're good to go if you want to use this a little bit more in depth carry on this is where the tutorial is going to kick off a little bit more so for starters what we're going to do is we're actually going to grab every single type of bond and we're going to delete all the cups we do not actually need the top part in the cup so simply select it in the collection and hit delete you can see it didn't really appreciate that but we're going to delete it anyway and again we're going to do that for every type of bond delete the cups here for the oxygen delete it for the fluorine and the reason that we're doing this is we're going to actually link all of these into a single mesh object we don't want the extra face on the top it's going to interfere with shading it's going into it's just going to add extra geometry to the scene it's very unnecessary and let's see our carbon one is gone as well so we'll start with carbon and this is the simplest approach we're actually going to hide the cylinder as well simply grab any of the bonds we'll start with the carbon one hit ctrl a and then we're going to choose make instances real when you do that all of the instance geometry is now actually real geometry in those places what you want to do from here is hold down shift and click any of these rings it doesn't matter which now you have an active object you can see that's the yellow one hit ctrl j and that will link them all so now this is one mesh entirely this means we can actually delete everything underneath it and now that i've selected it you can see these are all the planes that the cylinders were being mapped to before so we're just going to right click here and delete hierarchy so it's going to delete everything that was linked below now we can right click shade smooth which we already did before so it is smooth but one thing that we really want to do is acknowledge that these were individual cylinders that we've now linked together so we're going to tab into edit mode everything's going to be selected by default if it's not simply hit a to select everything then hit m and choose merge by distance and you can see we've removed a very substantial number of vertices and it's not going to impact our shading at all it just means that whereas this was now one cylinder before linked to another all the verts here have merged all the verts here have merged so it is one continuous object and essentially we would do the same thing for everything else in the scene if that seems a little tedious it is but it's going to be worthwhile at the end so again we'll do the same thing for the nitrogens grab the bond in question and if you have nitrogen here and over here it's going to impact all of them at once so ctrl a make instances real remember to delete the cups first which we already did then shift and click any one of these ctrl j to merge them all now i can right click shade smooth i can tab into edit mode hit m and merge by distance and you can see again we've lost a good number of verts and i can come back to the nitrogen from before if i want to and i can delete everything under this mesh right here so take all of these and delete hierarchy now we have just this mesh i actually like to merge all of my bonds and then all of my atoms separately and you can see when atomic blender imported this it gave names to all the materials that's super convenient and so we're going to take advantage of that we have our carbon here we're going to shift and click our nitrogen these are two separate meshes and again we're going to hit ctrl j so now our bonds are all going to be linked and we can do the same thing for our other bonds the last two being fluorine and oxygen so i'm going to quickly do that and then we'll come back now i'm going to link all the bonds so holding starting with any bond holding down shift and clicking all the different colors and there we go ctrl j so we now have a network of all of our bonds and that is actually this object right here it happens to be named oxygen sticks just because that's the last one we labeled and i'm actually going to relabel it as bonds and i'm going to hit m and move it to a new collection called cipro molecule so this is outside the previous collection now we're going to do something similar for the atoms you may remember at the beginning when we imported this i said leave it on nurbs if you don't really care personally i think it's better to actually have it on mesh so nurbs is what this little icon is here mesh is what i personally prefer to work with and we're actually going to convert this to mesh but the idea is the same grab every single atom hit control a make instances real then you're going to shift and click one of those atoms ctrl j to join them all f3 or whatever your search hotkey is and convert to mesh from curve meta surface text so now these are all mesh objects again we could right click shade smooth and if we wanted to we could now apply a subdivision surface modifier to all these to make them extra smooth if that's something you feel is necessary again i'm going to do the same thing for all the atoms and then i'm going to move them to another collection one thing that you want to note here is that even if there is only one atom you still need to make the instance real and do all the conversion and now we have all our atoms so we can do the same thing that we did before namely shift and click the individual spheres they're all linked so you can just do this and then ctrl j so now all our atoms are one mesh again oxygen ball just because that's the last one we selected i'm going to rename this atoms and i'm going to hit m again and move this to our cipro molecule collection so you can now see we have our atoms and our bonds together i'm going to then delete everything here under this collection by simply coming to the top of it right clicking and choosing delete hierarchy and again this is why you can see that i've missed an atom inconveniently so i'm going to double back just a bit this somehow didn't make it into the mesh so we're going to ctrl j and join that again you can see that's not okay because again i forgot to convert this to a mesh so convert it to mesh first tab and edit mode to confirm yes then we can merge it and now it belongs to that atoms collection so doubling back we're going to delete this whole hierarchy and you can see we have just our atoms and our bonds the reason that i've kept them separate for now is just so that i can set up the materials here similar to what i mentioned before i'm going to grab this object and you can see it's got all of these nicely labeled molecules or rather than all every individual atom has its own material and that is nicely labeled however they're being shared between the atoms and the bonds and the reason that i want to separate them now is just so that it's going to be easier when i merge the whole thing into one object so simply for each one of these choosing either your atoms or your bonds i prefer to work with the atoms come in and just click this little button here and then you can rename this material specifically to oxygen atoms i'm going to do the same thing for the carbon that i renamed earlier carbon atoms nitrogen let's do that again click that nitrogen atoms that t does not need to be capitalized and finally for the fluorine clicking the button again here we go fluorine atoms and that means that all the materials here are separate and they're for bonds so i can change these independent of one another which means i can now shift or grab my bonds shift and click my atoms ctrl j and this whole ciprofloxacin molecule is a single molecule and that has given me quite a bit of power to do certain things for starters i'm going to right click set origin and move it to origin to geometry so now it'll rotate about the middle of this molecule it also means i can use this as an individual object or mesh i can apply modifiers to the whole thing at once which is kind of interesting if you want to add something like say a wave now i can contort the whole thing and i wouldn't be able to do that before without having to manage multiple modifiers and more importantly in my mind i can actually use this as a particle so right now i'm just going to go ahead and relabel this as ciprofloxacin i'm going to come in and i'm going to set up some of the shading the way that i want it so let's say i want my oxygen atoms to be a little bit more of a red i can do that again through nodes so i'll hit use nodes that resets it but this time i'll go in and i'll customize that red so that it's darker than the bonds but also much more reflective so something like this i'll come to material preview to show that off a little bit better i'm not happy with say the way the carbon atoms are so i'll come in with those again and i'll make them significantly more reflective as well and i'd actually like them to be darker so i'll go ahead and pull those down maybe i want my carbon bonds to actually be more metallic so i'll drag that metallic value up to 1 i'll drag the roughness down to 0.25 and now you can see we have these nice silvery bonds clearly the nitrogen looks out of place here so that has to be fixed those will be much more blue again i just happen to like these things kind of shiny but you could set this up however you want and the nitrogen atoms likewise i can change those and i'll make them a little bit more purple blue because again i have the ability to do that having separated them and we'll stick with that for the time being fluorine should obviously be some sort of obnoxiously toxic green so we're going to go with that and we're going to change it for the bond as well now obviously if you just want all of them to be the same don't bother separating materials because you won't have to update multiple things now let's get into how we could use this to set up a scene in a kind of interesting way so i'm going to just grab this molecule hit h to hide it and then shift a add in a default cube and i'm going to add a number of array modifiers so come to modifier properties add in an array and we're going to enable merge drag a number of counts up let's say five and then this is a nice little feature of blender 2.9 i'm going to hover my mouse over here hit shift d and i've now duplicated that array with the merge enabled so i'm just going to change this to y drop the x to zero and then i'm going to do that one more time hovering over here shift e and i'm going to make this one one in the z direction zero in the y direction so i have a five by five by five grid now the reason that i want that is i'm going to use it to place particles if you look at the wireframe you can come in you can say okay five by five by five let's say 125 possible positions so i'm going to add a particle system through the particle properties tab and then i'm going to use hair for the number i let's say i want six ciprofloxacin molecules in this space i'm going to come to source enable emit from verts use the modifier stack keep random order and then for render now instead of having to deal with that whole collection which you can do but it's still going to cause you a lot of problems you can choose object and i'm going to choose my instance object to be ciprofloxacin that molecule so now i have six of these in space and if i come to material preview you can see the cube is blocking them but all i have to do is uncheck show emitter in render and also in viewport display so unchecking show emitter and now we have ciproflox and molecules kind of hanging out in space sort of randomly arranged we can mess with the scale of them from here we can make them different sizes we can also enable advanced options in the particle system enable rotation change to normal randomize the rotation randomize the phase and randomize sorry change the phase and randomize the velocity so now we have all these nice little handles for moving these around if i think i want a few more molecules i can change this number from say six to eight if i'm not happy with this distribution i can just explore different seed values until i find one that i like and this means that this is a very nice way to set up the molecule if you wanted you could also have multiple molecules put them into a collection and then use those in a particle system i'm not going to get into that here but it makes it a lot easier to set all these things up from there all i would have to do is let's say i like this i can hit control alt and number pad 0 snap my camera to view then i'll hit n to open the side panel come to view camera to view and then just sort of move around until it looks roughly the way that i want let's say i'm going to come at it from down here thereabouts i can enable a little bit of depth of field in my camera by coming to the object out of properties enabling depth field coming up to a rendered view zooming in and now i can change some of these values to make some of them blurry some of them more in focus by let's say lowering the f-stop to 1.8 i'd like this one to be in focus and the ones in the back to be blurry so i'm just going to adjust the focus distance until it sort of shows up where i want it to be and i'm just going to do that by scrolling this number in or out or dropping it down so that's obviously way out of view but if you want this as a background element totally fine drop that five let's say seven now and again this is just going to be exploring numbers you can also focus specifically and if you want this one of you and the ones in the back blurred simply lower this number even further once you have the focus rate so let's say 12 right there and i'm going to drop this number to 1.2 and that will make the ones in the back further out of focus the ones in the front more in focus and this is a very nice easy way to set up multiple molecules in a scene and everything from start to finish so get your molecule design it either customize it in avogadro by hand or import it using the incredible power of that functionality convert to open babel if you need all the extra bonds if you don't just save as pdb import the pdb file here use it as is if you just want the one molecule condense it as described in this tutorial if you want to use multiple ones and then you can use particle systems modifiers all kinds of things to set up multiple molecules in your scene very quickly and because this is all linked to this original cube i can shrink this in or out i can modify the cube by say adding a wave modifier to the cube and then moving that up so now if i want all my molecules can actually vibrate in space by moving it above the particle system so they're all going to jump up and down and kind of a fun way and i could change this or customize it if i wanted to now essentially that is the entirety of the details for how you would ever have to set up a molecule in blender if you really really want to stick around for what is already a long video i'm going to go for a few extra things just to show you how you can do dash bonds if you are particularly concerned with that or if you want to do sort of stylized ones using the normal imports we're going to control n start a new scene and then again delete the default cube we'll start with a stylized version and let's go ahead hit import pdb this time we're going to actually change to skin we're going to use these settings you notice that we no longer have access to multiple bonds but this is kind of interesting we're going to change the mesh here so i'm going to import and i'm actually going to hide all of these orbs so this is actually the one setting i mentioned before and it's sort of comically oversized we're going to hide all the atoms and then you can see that we have this really intriguing underlying mesh it's not going to show all of the actual structure or the atoms but it is kind of neat so if you want to work with something like this this is an option that is available you can see it has this sort of smoothing option to it and you can do all kinds of things you can actually create armatures to move this around i'm not going to get into that but it is an option and the last thing that we're going to do is just set all this up again and i'll show you the dash bonds so finally i'm going to very quickly show how you can do dash bonds in double or triple bonds once again we have our silver flocks in i'm going to zoom in this is our duplivert setup and first you're going to notice that we are in edit mode i'm then also going to hit z and tab into wireframe and or rather just enter into wireframe what i'm then going to do is i'm going to hit c and i'm going to select essentially all of the planes in here that i do not want to keep namely these ones if you hit some of the ones on other bonds don't worry the atoms are actually going to block that so it's not going to get in the way then i'll right click hit x and i'm going to delete those faces you do want to be in face select mode when you do this because you don't want to leave stray vertices now these faces right here are the ones that i'm going to use for that dash bond in fact i'd like this to be a little bit more balanced so i'm going to grab these two with c select again right click to exit that x and delete those faces so once you've deleted all the faces you don't want you c-select grab this set of planes here then making sure with the period key that we are on medium point we're simply going to hit s and scale until these separate and you can actually see the wireframe cylinder separating that's going to give our dashed bond now i'm going to drag this until just about here i can already tell that i'm going to have to delete those two planes probably and we're just going to do that right away by again hitting c selecting this one selecting this one right click and then x and delete faces and now again what we want to do one last time is actually make these planes small because if i came back into solid view now and then to object mode you could actually see them so what we're going to do is tab we're going to hit the period key we're going to choose individual origins with all the planes selected and then i'm just going to hit s and scale those in until they are hidden again and now if we come back into object mode which we are actually in deselect you can see we have a dash bond instead of the full double bonds this is just a stylization if you want and again because we're in dupliverts all you have to do to smooth this out is grab this specific object make it visible you can see it's right there grab it right click and shade smooth and obviously this would be a lot of work for every single bond if you want to go ahead and do it but that is up to you if it is something that you think is going to really add to your figure and with that i'm going to close off here so again crystals soon to follow just in terms of lattice's structures and a similar approach but otherwise every molecule that you could ever hope to make in blender from start to finish if you found this video useful consider subscribing sharing with your friends and colleagues until next time you have yourselves a great old day
Info
Channel: CG Figures
Views: 19,443
Rating: undefined out of 5
Keywords:
Id: zXJKYvuCPYY
Channel Id: undefined
Length: 30min 32sec (1832 seconds)
Published: Tue Oct 13 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.