Allink  v0.1
Dinamica.cpp
1 /***********************************************************************
2 ElPoly:This progam provide a graphical visualisation of the data
3 opend by VarData using openGL glut. The most important option are
4 the possibility of changing the backfold of the polymers with 'c',
5 see the subsequent file in the list with '>', see the bond with 'b'.
6 Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it>
7 
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ***********************************************************************/
23 #include "Forces.h"
24 #include <signal.h>
25 #include <fenv.h>
26 void Legenda();
27 void Particle();
28 void DrawParticle();
29 void keyboard(unsigned char key,int x, int y);
30 void InitConstant();
31 Forces *Fm;
32 static volatile int IfExit = 0;
33 static int IfUser = 1;
34 
35 static void StopLoop(int sig)
36 {
37  IfExit = 1;
38  printf("Loop stopped\n");
39 }
40 int main(int argc,char **argv){
41  char Comando[50];
42  char ConfFile[256];
43  signal(SIGTSTP,StopLoop);
44  signal(SIGSTOP,StopLoop);
45  signal(SIGSTOP,StopLoop);
46  // frame = (char *)malloc(100*sizeof(char));
47  //SpecFuntore <Matematica> SpecMat(&Mat,Matematica::Eval);
48  //SpecFuntore <ElPoly> SpecPol(&Pol,ElPoly::ContactAngle);
49  if(argc <2){ printf("ConfFile not specified\n"); return 1;}
50  int NEdge = 20+1;
51  //Fm->Solve();
52  int *FilePos = (int *)calloc(argc,sizeof(int));
53  int NFile = 0;
54  char Snapshot[60];
55  int InitFile = 0;
56  // ScaleUn = Fm->Gen->Edge[0];
57  //Principal(argc,argv);
58  for(int i=1;i<argc;i++){
59  if(argv[i][0] != '-'){
60  FilePos[NFile] = i;
61  NFile++;
62  }
63  else if(!strcmp(*(argv+i),"-d")){
64  sprintf(Comando,"d");
65  IfUser = 0;
66  }
67  else if(!strcmp(*(argv+i),"-r")){
68  sprintf(Comando,"r");
69  IfUser = 0;
70  }
71  else if(!strcmp(*(argv+i),"-s")){
72  sprintf(Comando,"s");
73  IfUser = 0;
74  }
75  else if(!strcmp(*(argv+i),"-c")){
76  if(argc > i){
77  sprintf(ConfFile,"%s",argv[i+1]);
78  i++;
79  }
80  else {
81  printf("Missing config file\n");
82  }
83  }
84  else if(!strcmp(*(argv+i),"-i")){
85  if(argc > i){
86  sprintf(Snapshot,"%s",*(argv+i+1));
87  InitFile = i + 1;
88  }
89  else{
90  printf("Snapshot file missing\n");
91  }
92  }
93  else if(!strncmp(*(argv+i),"--",2)){
94  sprintf(Comando,"%s",argv[i]+2);
95  IfUser = 0;
96  }
97  }
98  if(InitFile)
99  Fm = new Forces(argc,argv,ConfFile,argv[InitFile]);
100  else
101  Fm = new Forces(argc,argv,NEdge,ConfFile);
102  fedisableexcept(FE_ALL_EXCEPT);
103  char cSystem1[STRSIZE];
104  char cSystem2[STRSIZE];
105  Fm->SysInfo(cSystem1);
106  Fm->SysDef(cSystem2);
107  printf("------------------------------------------------------\n");
108  printf("%s NFile %d\n%s\n",cSystem1,NFile,cSystem2);
109  printf("------------------------------------------------------\n");
110  while(strcmp(Comando,"q")){
111  if(IfUser){
112  printf("Dinamica> ");
113  scanf("%s",Comando);
114  }
115  if(!strcmp(Comando,"d")){
116 #ifdef __glut_h__
117  Fm->Graphics(argc,argv);
118 #else
119  printf("Graphics libraries (GL/glut.h) not supplied\n");
120 #endif //__glut_h__
121  if(!IfUser) return 0;
122  }
123  else if(!strcmp(Comando,"s")){
124  Fm->RunDynamics();
125  if(!IfUser) return 0;
126  }
127  else if(!strcmp(Comando,"r")){
128  Fm->RunDynamics();
129  if(!IfUser) return 0;
130  }
131  else if(!strcmp(Comando,"nrg")){
132  for(int f=0;f<NFile;f++){
133  fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
134  Fm->CalcTotNrg(argv[FilePos[f]],f);
135  }
136  if(!IfUser) return 0;
137  }
138  else if(!strcmp(Comando,"PepNrg")){
139  for(int f=0;f<NFile;f++){
140  fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
141  Fm->CalcNrgPep(argv[FilePos[f]],f);
142  }
143  if(!IfUser) return 0;
144  }
145  else if(!strcmp(Comando,"ExpPep")){
146  Fm->ExplorePepSize();
147  if(!IfUser) return 0;
148  }
149  else if(!strcmp(Comando,"ExpPep2d")){
150  Fm->ExplorePepSize2d();
151  if(!IfUser) return 0;
152  }
153  else if(!strcmp(Comando,"ExpDist")){
154  Fm->ExploreDoubleMin();
155  if(!IfUser) return 0;
156  }
157  else if(!strcmp(Comando,"Widom")){
158  for(int f=0;f<NFile;f++){
159  fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
160  Fm->RunWidom(argv[FilePos[f]],f);
161  }
162  if(!IfUser) return 0;
163  }
164  else if(!strcmp(Comando,"WidomChIn")){
165  for(int f=0;f<NFile;f++){
166  fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
167  Fm->RunWidomChIn(argv[FilePos[f]],f);
168  }
169  printf("\n");
170  if(!IfUser) return 0;
171  }
172  else if(!strcmp(Comando,"WidomChOut")){
173  for(int f=0;f<NFile;f++){
174  fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
175  Fm->RunWidomChOut(argv[FilePos[f]],f);
176  }
177  printf("\n");
178  if(!IfUser) return 0;
179  }
180  else if(!strcmp(Comando,"Rosenbluth")){
181  char File2Write[60];
182  for(int f=0;f<NFile;f++){
183  sprintf(File2Write,"Rosenbluth%05d.dat",f);
184  FILE *WidomIn = fopen(File2Write,"w");
185  fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
186  Fm->ReOpen(argv[FilePos[f]],BF_PART);
187  Fm->RosenIn(WidomIn);
188  fclose(WidomIn);
189  }
190  printf("\n");
191  if(!IfUser) return 0;
192  }
193  else if(!strcmp(Comando,"RosenOut")){
194  char File2Write[60];
195  for(int f=0;f<NFile;f++){
196  sprintf(File2Write,"RosenOut%05d.dat",f);
197  FILE *WidomIn = fopen(File2Write,"w");
198  fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
199  Fm->ReOpen(argv[FilePos[f]],BF_PART);
200  Fm->RosenOut(WidomIn);
201  fclose(WidomIn);
202  }
203  printf("\n");
204  if(!IfUser) return 0;
205  }
206  else if(!strcmp(Comando,"Tens")){
207  Fm->CalcTens(argv,FilePos,NFile);
208  if(!IfUser) return 0;
209  }
210  else if(!strcmp(Comando,"AvForces")){
211  Fm->AvForces(argv,FilePos,NFile);
212  if(!IfUser) return 0;
213  }
214  else if(!strcmp(Comando,"Trial")){
215  Fm->Trial();
216  if(!IfUser) return 0;
217  }
218  else if(!strcmp(Comando,"?") ){
219  Legenda();
220  }
221  else if(!strcmp(Comando,"!") ){
222  printf("Insert a shell command: ");
223  scanf("%s",Comando);
224  system(Comando);
225  }//-----------------System-Info---------------------------
226  else if(!strcmp(Comando,"info")){
227  printf("------------------------------------------------------\n");
228  //printf("%s\n",Fm->SysInfo());
229  }
230  else if(!strcmp(Comando,"write") ){
231  Fm->Write("ciccia.dat");
232  }
233  else if(!strcmp(Comando,"q") );
234  else {
235  IfUser = 1;
236  printf("Comando non valido, scrivere ? per la lista dei comandi\n");
237  }
238  }
239  printf("Te se qe te ve be te ne?\n");
240  return 0;
241 }
242 #ifdef __glut_h__
243 void ParticleList(){
244  Fm->DrawScene();
245 }
246 // void ParticleRealTime(){
247 // //Fm->DrawNano();
248 // }
249 // void InitConstant(){
250 // Fm->InitConstant();
251 // }
252 void keyboard(unsigned char key,int x, int y){
253  Fm->keyboard(key,x,y);
254 }
255 void Menu(){
256  Fm->Menu();
257 }
258 void DynamicsMotion(){
259  Fm->DynamicsView();
260 }
261 #endif
262 void Legenda(){
263  printf("\n\
264 *****************************************************************\n\
265 ( )\n\
266 ) Program that reads and elaborate a spefic file format (\n\
267 ( the option are the following, Needs a input file )\n\
268 ) (\n\
269 (-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-)\n\
270 ( d draw the 3D position of the particle )\n\
271 ( ! execute a shell command )\n\
272 ( q quit )\n\
273 ( dens density of the [coord] coordinate for the [file] )\n\
274 ( pro calculate the projection long [coord] )\n\
275 ( threshold set how many particle per cell will be considered )\n\
276 ( surf ratio between the actual surcafe and the circular )\n\
277 ( core three dimentional sampled average of the system )\n\
278 ( diff diffusivity of the extra particle )\n\
279 ( > < open the file form the list position )\n\
280 ( cm movement of the center of mass of the system )\n\
281 ( file number of file to use from the list )\n\
282 ( info ... )\n\
283 ( chbf change backfold )\n\
284 ( val number of values for the density profile )\n\
285 *****************************************************************\n");
286 }
void RunDynamics()
Run a step further.
Definition: ForcesLoop.cpp:455
void CalcTens()
Calculate the forces for the tension profile.
Definition: ForcesTens.cpp:85
void ExplorePepSize2d()
Find the minimun bilayer thickness for different peptide sizes.
Definition: ForcesLoop.cpp:145
void keyboard(unsigned char key, int x, int y)
Additional key bindings.
Definition: ForcesDraw.cpp:384
void CalcTotNrg(char *FName, int nFile)
Total energy of the system.
Definition: ForcesLoop.cpp:293
void Trial()
Trial loop.
Definition: ForcesLoop.cpp:452
void SysDef(char *cSystem)
Print a string with the system definitions.
Definition: VarData.cpp:167
void SysInfo(char *cSystem)
Print a string with the system information.
Definition: VarData.cpp:164
void RunWidom(char *File2Read, int f)
Build the widom histograms.
Definition: ForcesLoop.cpp:223
bool Write(char *OutFile)
Writes a "system-file" or a "x y z" file".
void DrawScene()
Draw the scene.
Definition: ForcesDraw.cpp:51
void RunWidomChIn(char *File2Read, int f)
Build the widom histograms.
Definition: ForcesLoop.cpp:263
void CalcNrgPep(char *File2Open, int f)
Exchange energy of the protein.
Definition: ForcesLoop.cpp:333
void ExploreDoubleMin()
Find the minimum for different interpeptide distances.
Definition: ForcesLoop.cpp:170
void RosenOut(FILE *WidomIn)
Rosenbluth histograms for deletion.
Definition: ForcesLoop.cpp:254
void Menu()
Menu.
Definition: ForcesDraw.cpp:374
void ReOpen(char *FName, int Bf)
Open a new file.
Definition: Forces.cpp:901
void ExplorePepSize()
Find the minimun bilayer thickness for different peptide sizes.
Definition: ForcesLoop.cpp:97
void RosenIn(FILE *WidomIn)
Rosenbluth weights for insertion.
Definition: ForcesLoop.cpp:245
void RunWidomChOut(char *File2Read, int f)
Build the widom histograms.
Definition: ForcesLoop.cpp:279
int Graphics(int argc, char **argv)
Initialize the scene.
Definition: ForcesDraw.cpp:6
This class performs the different steps to solve the equations of motion via molecular dynamics simul...
Definition: Forces.h:223
void DynamicsView()
Idle function to run the dynamics.
Definition: ForcesDraw.cpp:57
void AvForces(char **argv, int *FilePos, int NFile)
Average of the forces.
Definition: ForcesLoop.cpp:375