A VMD script for auto-changing color and style
By Cun Zhang | April 4, 2011
VMD is a great MD tool for the pre- and post-processing of MD simulations which supports scripting.
Your can write your script(e.g. test.tcl), then run it with "vmd -e test.tcl" in bash console
or "source test.tcl" in vmd console. So it's easy and convenient
when you do similar processings with vmd.
Here is a script which I used to observe some details in my MD simulation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #author: cunzhang (apzc2529@tom.com) #homepage: http://edwardpku.com/cun/ # load file mol load lammpstrj ini.lammpstrj xtc dump.xtc ## set different names for color [atomselect top "residue 0 and type 1"] set name 0 [atomselect top "residue 1 and type 1"] set name 1 [atomselect top "type 2"] set name H [atomselect top "residue 2 and type 1"] set name 3 [atomselect top "((residue 1 and x**2+y**2>120 and y< -6 and x<-7) or (x<-17)) and type 1" frame 0] set name 4 ## change the color of background and Atoms color Display Background iceblue color Name 0 green color Name 1 pink #color Name 2 blue color Name 3 green color Name 4 red ## change atom styles. mol addrep 0 mol modselect 1 0 "name 4" mol modstyle 1 0 dynamicbonds 1.6 0.3 50 |
Topics: Uncategorized | No Comments »
Protected: 想和你去吹吹风
By Cun Zhang | April 3, 2011
Topics: Uncategorized | Enter your password to view comments.
A MPI4PY Example
By Cun Zhang | March 20, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #!/usr/bin/python from mpi4py import MPI comm=MPI.COMM_WORLD size=comm.Get_size() rank=comm.Get_rank() if rank==0: result=0 x=range(1,151) else: x=None x=comm.bcast(x,root=0) N=len(x)/size low=rank*N high=low+N myresult=0 result=[] for i in range(low,high): myresult+=x[i] result=comm.reduce(myresult,root=0) if rank == 0: for i in range(size*N,len(x)): result=result+x[i] print result,sum(x) MPI.Finalize() |
Topics: Uncategorized | No Comments »
Python Ctypes Example
By Cun Zhang | March 29, 2010
- Write the C code
- Compile c code into share library
- call c function in python
I write a c source file named exam.c as follows:
#include <stdio .h> #include <math .h> long int sum1(int I,int J){ int i,j; long int s=0; for(i=1;i< =I;i=i+1){ for(j=1;j<=J;j=j+1){ s=s+i+j; } } return s; } void sum2(int I,int J,long int *s){ int i,j; *s=0; for(i=1;i<=I;i=i+1){ for(j=1;j<=J;j=j+1){ *s=*s+i+j; } } return; } void main(){ int i=10000; long int s1,s2; sum2(i,i,&s2); printf("%ld\n",s2); } |
cunzhang@Debian:~$ gcc -c -fPIC exam.c cunzhang@Debian:~$ gcc -shared exam.o -o exam.so |
cunzhang@Debian:~$python exam.py cunzhang@Debian:~$ cat exam.py |
#!/usr/bin/python from ctypes import * exam=CDLL('/home/cunzhang/exam.so') I=c_long(10000) S=c_long() exam.sum1.restype=c_long x=exam.sum1(I,I) exam.sum2(I,I,byref(S)) print x,S.value |
Topics: Uncategorized | 1 Comment »
Prevent xscreensaver from blanking when watching movies
By Cun Zhang | January 15, 2010
How do I prevent xscreensaver from blanking the screen when
I'm watching movies on my computer?
If you are using a recent version of
MPlayer, put this
in your ~/.mplayer/config file:
-
heartbeat-cmd="xscreensaver-command -deactivate"
If you're using something other than MPlayer:
-
When you want to watch a movie, fire up
xscreensaver-demo and select
Mode: Disable Screen Saver from the option menu, which means
not to blank the screen at all. When you're done watching the movie,
re-select your previous mode.
That's kind of lame, I know. You should ask the author of the
movie-playing software you are using to add explicit support for
xscreensaver to their program.
If you are the author of movie-playing software:
The way you prevent xscreensaver from blanking the screen
while a movie is playing is something like this:
if (playing && !paused) {
system ("xscreensaver-command -deactivate >&- 2>&- &");
}
Though it would be better to code this using fork()
and execvp() instead of system().
That will prevent the screen saver from activating while the
movie is playing, but will allow it to activate normally while the
movie is stopped or paused. You probably ought to make this
behavior a preference, so that you don't permanently deactivate the
screen saver when, for example, someone is playing movies in a loop
on their root window, or when your player is being used as a web
page plugin.
The reason to do this with a timer (instead of turning the
screensaver off and then on again in some other way) is so that if
your program crashes, you're guaranteed that the screensaver will
not be left in a permanently disabled state.
If you think this is "too inefficient," you're mistaken.
(You haven't actually timed it, have you? I didn't think so.)
Please also consider adding a command-line option to your
movie player to let it play movies in a loop on the root window,
with the GUI controls hidden, so that your program can be used to
play movies as a screen saver!
From: http://www.jwz.org/xscreensaver/faq.html
Topics: Uncategorized | No Comments »