POV-Ray : Newsgroups : povray.newusers : Crystal made of millions of atoms Server Time
29 Oct 2024 22:45:09 EDT (-0400)
  Crystal made of millions of atoms (Message 1 to 4 of 4)  
From: Tomohiro
Subject: Crystal made of millions of atoms
Date: 8 Jul 2010 02:30:00
Message: <web.4c356f946fc022ce6aeee4e0@news.povray.org>
Hello,

I would like to build an image of a crystal made of a lot of atoms
and chemical bonds. I wrote a following source file, but it is very
heavy and sometimes causes shortage of memory. Also, it is very slow.
Please change the Lattice_Constant value in the source file from 0.5
to 0.01 to check what happens.
(Since my final goal is to build an animation, faster rendering is
better.)

I also tried an isosurface with a function like:
  function{ 0.3 - pow(cos(x/Lattice_Constant*pi),2)
                * pow(cos(y/Lattice_Constant*pi),2)
                * pow(cos(z/Lattice_Constant*pi),2) }
but the result image is something wrong.

I imagine there should be cleverer way to do this. Could someone
give hints?

//---------- source code ----------//

camera{ location <0.2,0.7,-1>  look_at <0,0,0> }
light_source{ <-200,200,-200> rgb<1,1,1> }
global_settings{ ambient_light rgb 3 }

#declare T_Atom = texture{pigment {rgb<.3, .5, .7>} finish{phong 0.3}}
#declare T_Bond = texture{pigment {rgb<.7, .5, .3>} finish{phong 0.3}}
#declare Lattice_Constant=0.05;
#declare Xmax=3;
#declare Ymax=0;
#declare Zmax=5;
#declare Xmin=-4;
#declare Ymin=-2;
#declare Zmin=0;

// Place atoms at lattice points
#declare X=Xmin; #while(X<=Xmax)
  #declare Y=Ymin; #while(Y<=Ymax)
    #declare Z=Zmin; #while(Z<=Zmax)
      sphere{ <X,Y,Z>, Lattice_Constant*0.3 texture{T_Atom} }
    #declare Z=Z+Lattice_Constant; #end
  #declare Y=Y+Lattice_Constant; #end
#declare X=X+Lattice_Constant; #end

// Place chemical bonds
#declare X=Xmin; #while(X<=Xmax)
  #declare Y=Ymin; #while(Y<=Ymax)
    cylinder{ <X,Y,Zmin>, <X,Y,Zmax>, Lattice_Constant*0.1 texture{T_Bond} }
  #declare Y=Y+Lattice_Constant; #end
#declare X=X+Lattice_Constant; #end

#declare X=Xmin; #while(X<=Xmax)
  #declare Z=Zmin; #while(Z<=Zmax)
    cylinder{ <X,Ymin,Z>, <X,Ymax,Z>, Lattice_Constant*0.1 texture{T_Bond} }
  #declare Z=Z+Lattice_Constant; #end
#declare X=X+Lattice_Constant; #end

#declare Z=Zmin; #while(Z<=Zmax)
  #declare Y=Ymin; #while(Y<=Ymax)
    cylinder{ <Xmin,Y,Z>, <Xmax,Y,Z>, Lattice_Constant*0.1 texture{T_Bond} }
  #declare Y=Y+Lattice_Constant; #end
#declare Z=Z+Lattice_Constant; #end


Post a reply to this message

From: clipka
Subject: Re: Crystal made of millions of atoms
Date: 8 Jul 2010 04:45:23
Message: <4c359023$1@news.povray.org>
Am 08.07.2010 08:27, schrieb Tomohiro:
> Hello,
>
> I would like to build an image of a crystal made of a lot of atoms
> and chemical bonds. I wrote a following source file, but it is very
> heavy and sometimes causes shortage of memory. Also, it is very slow.
> Please change the Lattice_Constant value in the source file from 0.5
> to 0.01 to check what happens.
> (Since my final goal is to build an animation, faster rendering is
> better.)

You might try using a blob object rather than individual spheres and 
cylinders. With well-chosen parameters the visual difference will be 
very low, and it will enable you to trim down memory consumption 
significantly.

For best effect, #declare a blob with, say, 20x20x20 atoms, then place 
as many copies of this blob as you need.

Alternatively, you can use a so-called "infinity box", which will allow 
you to repeat the scene's contents /ad infinitum/; this way, you'll only 
need to model a single "cell" of the lattice, so you'll need even less 
memory than the blob approach. There's a sample scene for this approach 
(scenes/advanced/infinitybox.pov).

I'm not sure which of these approaches gives better rendering speed though.


Post a reply to this message

From: gregjohn
Subject: Re: Crystal made of millions of atoms
Date: 17 Jul 2010 09:35:01
Message: <web.4c41b09d2122fbf434d207310@news.povray.org>
"Tomohiro" <nomail@nomail> wrote:
> Hello,
>
> I would like to build an image of a crystal made of a lot of atoms
> and chemical bonds. I wrote a following source file, but it is very
> heavy and sometimes causes shortage of memory. Also, it is very slow.


One potential solution would be to create only those items which are in the
field of view at the moment. It would just require some creative bounding in
your for-next loops.  In theory you could explore infinite space but only PARSE
the items which will happen to be in the field of view at the moment.


Post a reply to this message

From: Tomohiro
Subject: Re: Crystal made of millions of atoms
Date: 18 Jul 2010 11:10:00
Message: <web.4c4318c12122fbf4346f4c500@news.povray.org>
I tried blob and it was true that it reduced time and memory significantly,
but it was not enough.

Thus I used isosurface's with functions of

 0.55 - abs(cos(x/Dist*pi) * cos(y/Dist*pi) * cos(z/Dist*pi))    for atoms
 0.89 - abs(cos(y/Dist*pi) * cos(z/Dist*pi))                     for bonds

where Dist is the lattice constant, while it is not a true sphere.
Last time I wrote the result was something wrong but I found that
usage of max_gradient value of about 3000 - 5000 will give a
good result. This was faster than usage of blob.

However, even using sufficiently large max_gradient, some small
artifacts remain. The artifacts seem to be related to shadow on
an "atom" or a "bond" from other "atoms" or "bonds".


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.