}
int set_temperature(t_moldyn *moldyn,double t) {
-
+
moldyn->t=t;
return 0;
int i;
double e,scale;
t_atom *atom;
+ int count;
atom=moldyn->atom;
*/
e=0.0;
- for(i=0;i<moldyn->count;i++)
- e+=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
- scale=(1.5*moldyn->count*K_BOLTZMANN*moldyn->t)/e;
+ count=0;
+ for(i=0;i<moldyn->count;i++) {
+ if(atom[i].attr&ATOM_ATTR_HB) {
+ e+=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
+ count+=1;
+ }
+ }
+
+ /* temporary hack for e,t = 0 */
+ if(e==0.0) {
+ if(moldyn->t!=0.0)
+ thermal_init(moldyn);
+ else
+ return 0;
+ }
+
+ /* direct scaling */
+ scale=(1.5*count*K_BOLTZMANN*moldyn->t)/e;
if(type&VSCALE_INIT_EQUI) scale*=2.0; /* equipartition theorem */
scale=sqrt(scale);
for(i=0;i<moldyn->count;i++)
- v3_scale(&(atom[i].v),&(atom[i].v),scale);
+ if(atom[i].attr&ATOM_ATTR_HB)
+ v3_scale(&(atom[i].v),&(atom[i].v),scale);
return 0;
}