Measure.C File Reference

#include "InfoStream.h"
#include "Measure.h"
#include "Node.h"
#include "Parameters.h"
#include "Molecule.h"

Go to the source code of this file.

Functions

static int Tcl_centerOfNumber (ClientData, Tcl_Interp *interp, int argc, char *argv[])
static int Tcl_centerOfMass (ClientData, Tcl_Interp *interp, int argc, char *argv[])
static int Tcl_radiusOfGyration (ClientData, Tcl_Interp *interp, int argc, char *argv[])
static int Tcl_loadCoords (ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])


Function Documentation

static int Tcl_centerOfMass ( ClientData  ,
Tcl_Interp *  interp,
int  argc,
char *  argv[] 
) [static]

Definition at line 55 of file Measure.C.

References Molecule::atommass(), Node::coords, Node::molecule, Molecule::numAtoms, Node::Object(), Vector::x, Vector::y, and Vector::z.

Referenced by Measure::createCommands().

00055                                                                                     {
00056 
00057   Node *node = Node::Object();
00058   Molecule *molecule = node->molecule;
00059   // Parameters *parameters = node->parameters;
00060   Vector *coordinates = node->coords;
00061   int numAtoms = molecule->numAtoms;
00062 
00063   Vector center = 0;
00064   BigReal totalMass = 0;
00065   for( int i = 0; i < numAtoms; ++i ) {
00066     BigReal mass = molecule->atommass(i);
00067     totalMass += mass;
00068     center += mass * coordinates[i];
00069   }
00070   center /= totalMass;
00071 
00072   char s[1024];
00073   sprintf(s,"%g %g %g", center.x, center.y, center.z);
00074   Tcl_SetResult(interp,s,TCL_VOLATILE);
00075 
00076   return TCL_OK;
00077 }

static int Tcl_centerOfNumber ( ClientData  ,
Tcl_Interp *  interp,
int  argc,
char *  argv[] 
) [static]

Definition at line 32 of file Measure.C.

References Node::coords, Node::molecule, Molecule::numAtoms, Node::Object(), Vector::x, Vector::y, and Vector::z.

Referenced by Measure::createCommands().

00032                                                                                       {
00033 
00034   Node *node = Node::Object();
00035   Molecule *molecule = node->molecule;
00036   // Parameters *parameters = node->parameters;
00037   Vector *coordinates = node->coords;
00038   int numAtoms = molecule->numAtoms;
00039 
00040   int number = 0;
00041   Vector center = 0;
00042   for( int i = 0; i < numAtoms; ++i ) {
00043     number += 1;
00044     center += coordinates[i];
00045   }
00046   center /= number;
00047 
00048   char s[1024];
00049   sprintf(s,"%g %g %g", center.x, center.y, center.z);
00050   Tcl_SetResult(interp,s,TCL_VOLATILE);
00051 
00052   return TCL_OK;
00053 }

static int Tcl_loadCoords ( ClientData  ,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[] 
) [static]

Definition at line 111 of file Measure.C.

References Node::coords, coords, Node::molecule, Molecule::numAtoms, Node::Object(), x, y, and z.

Referenced by Measure::createCommands().

00111                                                                                             {
00112   
00113   if (objc < 2 || objc > 3) {
00114     Tcl_SetResult(interp,"loadCoords: wrong # args",TCL_VOLATILE);
00115     return TCL_ERROR;
00116   }
00117   Tcl_Obj * const vname = objv[1];
00118   Node *node = Node::Object();
00119   Molecule *molecule = node->molecule;
00120   // Parameters *parameters = node->parameters;
00121   const Vector *coords = node->coords;
00122   int numAtoms = molecule->numAtoms;
00123  
00124   if (objc == 2) {
00125     // get all the coordinates
00126     for (int i=0; i<numAtoms; i++) {
00127       Tcl_Obj *newlist = Tcl_NewListObj(0, NULL);
00128       Tcl_Obj *arrkey = Tcl_NewIntObj(i+1);
00129       Tcl_IncrRefCount(arrkey);
00130       Tcl_ListObjAppendElement(interp, newlist, 
00131         Tcl_NewDoubleObj(coords[i].x));
00132       Tcl_ListObjAppendElement(interp, newlist, 
00133         Tcl_NewDoubleObj(coords[i].y));
00134       Tcl_ListObjAppendElement(interp, newlist, 
00135         Tcl_NewDoubleObj(coords[i].z));
00136       if (!Tcl_ObjSetVar2(interp, vname, arrkey, newlist, 0))
00137         return TCL_ERROR;
00138       Tcl_DecrRefCount(arrkey);
00139     }
00140   } else {
00141     // third argument must be a list of indices
00142     int nelems;
00143     Tcl_Obj **elems;
00144     if (Tcl_ListObjGetElements(interp, objv[2], &nelems, &elems) != TCL_OK) {
00145       return TCL_ERROR;
00146     }
00147     for (int i=0; i<nelems; i++) {
00148       int ind; 
00149       if (Tcl_GetIntFromObj(interp, elems[i], &ind) != TCL_OK)
00150         return TCL_ERROR;
00151       Tcl_Obj *newlist = Tcl_NewListObj(0, NULL);
00152       Tcl_Obj *arrkey = Tcl_NewIntObj(ind);
00153       Tcl_IncrRefCount(arrkey);
00154       --ind;
00155       Tcl_ListObjAppendElement(interp, newlist, 
00156         Tcl_NewDoubleObj(coords[ind].x));
00157       Tcl_ListObjAppendElement(interp, newlist, 
00158         Tcl_NewDoubleObj(coords[ind].y));
00159       Tcl_ListObjAppendElement(interp, newlist, 
00160         Tcl_NewDoubleObj(coords[ind].z));
00161       if (!Tcl_ObjSetVar2(interp, vname, arrkey, newlist, 0))
00162         return TCL_ERROR;
00163       Tcl_DecrRefCount(arrkey);
00164     }
00165   }
00166   return TCL_OK;
00167 }

static int Tcl_radiusOfGyration ( ClientData  ,
Tcl_Interp *  interp,
int  argc,
char *  argv[] 
) [static]

Definition at line 79 of file Measure.C.

References Molecule::atommass(), Node::coords, Node::molecule, Molecule::numAtoms, and Node::Object().

Referenced by Measure::createCommands().

00079                                                                                         {
00080 
00081   Node *node = Node::Object();
00082   Molecule *molecule = node->molecule;
00083   // Parameters *parameters = node->parameters;
00084   Vector *coordinates = node->coords;
00085   int numAtoms = molecule->numAtoms;
00086 
00087   Vector center = 0;
00088   BigReal totalMass = 0;
00089   int i;
00090   for( i = 0; i < numAtoms; ++i ) {
00091     BigReal mass = molecule->atommass(i);
00092     totalMass += mass;
00093     center += mass * coordinates[i];
00094   }
00095   center /= totalMass;
00096 
00097   BigReal moment = 0;
00098   for( i = 0; i < numAtoms; ++i ) {
00099     BigReal mass = molecule->atommass(i);
00100     moment += mass * (coordinates[i] - center).length2();
00101   }
00102   BigReal radius = sqrt(moment/totalMass);
00103 
00104   char s[1024];
00105   sprintf(s,"%g", radius);
00106   Tcl_SetResult(interp,s,TCL_VOLATILE);
00107 
00108   return TCL_OK;
00109 }


Generated on Tue Sep 19 01:17:15 2017 for NAMD by  doxygen 1.4.7