ESPResSo 3.2.0-11-g9950804-git
Extensible Simulation Package for Soft Matter Research
statistics_molecule.c
Go to the documentation of this file.
00001 /*
00002   Copyright (C) 2010,2012,2013 The ESPResSo project
00003   Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 
00004     Max-Planck-Institute for Polymer Research, Theory Group
00005   
00006   This file is part of ESPResSo.
00007   
00008   ESPResSo is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   ESPResSo is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
00020 */
00021 /** \file statistics_molecule.c
00022 
00023     see \ref statistics_molecule.h
00024 */
00025 #include "statistics_molecule.h"
00026 #include "errorhandling.h"
00027 #include "grid.h"
00028 
00029 /* new version for new topology structure */
00030 int analyze_fold_molecules(float *coord, double shift[3])
00031 {
00032   int m,p,i, tmp;
00033   int mol_size, ind;
00034   double cm_tmp, com[3];
00035 
00036   /* check molecule information */
00037   if ( n_molecules < 0 ) return ES_ERROR;
00038 
00039   if (!sortPartCfg()) {
00040     char *errtxt = runtime_error(128);
00041     ERROR_SPRINTF(errtxt, "{059 analyze_fold_molecules: could not sort particle config, particle ids not consecutive?} ");
00042     return ES_ERROR;
00043   }
00044 
00045   /* loop molecules */
00046   for(m=0; m<n_molecules; m++) {
00047     mol_size = topology[m].part.n;
00048     if(mol_size > 0) {
00049       /* calc center of mass */
00050       calc_mol_center_of_mass(topology[m],com);
00051       /* fold coordinates */
00052       for(i=0; i<3; i++) {
00053         if ( PERIODIC(i) ) { 
00054           tmp = (int)floor((com[i]+shift[i])*box_l_i[i]);
00055           cm_tmp =0.0;
00056           for(p=0; p<mol_size; p++) {
00057             ind        = 3*topology[m].part.e[p] + i;
00058             coord[ind] -= tmp*box_l[i];
00059             coord[ind] += shift[i];
00060             cm_tmp     += coord[ind];
00061           }
00062           cm_tmp /= (double)mol_size;
00063           if(cm_tmp < -10e-6 || cm_tmp > box_l[i]+10e-6) {
00064             char *errtxt = runtime_error(128 + ES_INTEGER_SPACE + 2*ES_DOUBLE_SPACE);
00065             ERROR_SPRINTF(errtxt,"{060 analyze_fold_molecules: chain center of mass is out of range (coord %d: %.14f not in box_l %.14f)} ",
00066                     i,cm_tmp,box_l[i]);
00067             return ES_ERROR;
00068           }
00069         }
00070       }
00071     }
00072   }
00073   return ES_OK;
00074 }
00075 
00076 
00077 
00078 /* TODO: this function is not used anywhere. To be removed? */
00079 double calc_mol_hydro_radius(Molecule mol) 
00080 {
00081   int i, j, id1, id2;
00082   double rh=0.0, diff_vec[3];
00083 
00084   for(i=0; i<mol.part.n; i++) {
00085     id1 = mol.part.e[i];
00086     for(j=i+1; j<mol.part.n; j++) {
00087       id2 = mol.part.e[i];
00088       vecsub(partCfg[id1].r.p, partCfg[id2].r.p, diff_vec);
00089       rh += 1.0/sqrt(sqrlen(diff_vec));
00090     }
00091   }
00092   return 0.5*(mol.part.n*(mol.part.n-1))/rh;
00093 }
00094 
00095 
00096 /**Incorporates mass of each particle*/
00097 void calc_mol_center_of_mass(Molecule mol, double com[3])
00098 {
00099   int i,j,id;
00100   double M = 0.0;
00101   for(j=0; j<3; j++) com[j]=0.0;
00102 
00103   for(i=0; i<mol.part.n; i++) {
00104     id = mol.part.e[i];
00105     for(j=0; j<3; j++) com[j]+= partCfg[id].r.p[j]*PMASS(partCfg[id]);
00106     M += PMASS(partCfg[id]);
00107   }
00108     for(j=0; j<3; j++) com[j] /= M;
00109 }
00110 
00111 /* TODO: This function is not used anywhere. To be removed? */
00112 /**Incorporates mass of each particle*/
00113 double calc_mol_gyr_radius2(Molecule mol)
00114 {
00115   int i, id;
00116   double rg=0.0, M=0.0, com[3], diff_vec[3];
00117 
00118   calc_mol_center_of_mass(mol, com);
00119 
00120   for(i=0; i<mol.part.n; i++) {
00121     id = mol.part.e[i];
00122     vecsub(partCfg[id].r.p, com, diff_vec);
00123     rg += sqrlen(diff_vec);
00124     M += PMASS(partCfg[id]);
00125   }
00126 
00127   return (rg/M);
00128 }