NAMD
Functions
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, const char *argv[])
 
static int Tcl_centerOfMass (ClientData, Tcl_Interp *interp, int argc, const char *argv[])
 
static int Tcl_radiusOfGyration (ClientData, Tcl_Interp *interp, int argc, const 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,
const 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().

55  {
56 
57  Node *node = Node::Object();
58  Molecule *molecule = node->molecule;
59  // Parameters *parameters = node->parameters;
60  Vector *coordinates = node->coords;
61  int numAtoms = molecule->numAtoms;
62 
63  Vector center = 0;
64  BigReal totalMass = 0;
65  for( int i = 0; i < numAtoms; ++i ) {
66  BigReal mass = molecule->atommass(i);
67  totalMass += mass;
68  center += mass * coordinates[i];
69  }
70  center /= totalMass;
71 
72  char s[1024];
73  sprintf(s,"%g %g %g", center.x, center.y, center.z);
74  Tcl_SetResult(interp,s,TCL_VOLATILE);
75 
76  return TCL_OK;
77 }
static Node * Object()
Definition: Node.h:86
Definition: Node.h:78
Definition: Vector.h:64
BigReal z
Definition: Vector.h:66
BigReal x
Definition: Vector.h:66
int numAtoms
Definition: Molecule.h:557
Vector * coords
Definition: Node.h:185
BigReal y
Definition: Vector.h:66
Real atommass(int anum) const
Definition: Molecule.h:1042
Molecule * molecule
Definition: Node.h:176
double BigReal
Definition: common.h:114
static int Tcl_centerOfNumber ( ClientData  ,
Tcl_Interp *  interp,
int  argc,
const 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().

32  {
33 
34  Node *node = Node::Object();
35  Molecule *molecule = node->molecule;
36  // Parameters *parameters = node->parameters;
37  Vector *coordinates = node->coords;
38  int numAtoms = molecule->numAtoms;
39 
40  int number = 0;
41  Vector center = 0;
42  for( int i = 0; i < numAtoms; ++i ) {
43  number += 1;
44  center += coordinates[i];
45  }
46  center /= number;
47 
48  char s[1024];
49  sprintf(s,"%g %g %g", center.x, center.y, center.z);
50  Tcl_SetResult(interp,s,TCL_VOLATILE);
51 
52  return TCL_OK;
53 }
static Node * Object()
Definition: Node.h:86
Definition: Node.h:78
Definition: Vector.h:64
BigReal z
Definition: Vector.h:66
BigReal x
Definition: Vector.h:66
int numAtoms
Definition: Molecule.h:557
Vector * coords
Definition: Node.h:185
BigReal y
Definition: Vector.h:66
Molecule * molecule
Definition: Node.h:176
static int Tcl_loadCoords ( ClientData  ,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)
static

Definition at line 111 of file Measure.C.

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

Referenced by Measure::createCommands().

111  {
112 
113  if (objc < 2 || objc > 3) {
114  Tcl_SetResult(interp,(char*)"loadCoords: wrong # args",TCL_VOLATILE);
115  return TCL_ERROR;
116  }
117  Tcl_Obj * const vname = objv[1];
118  Node *node = Node::Object();
119  Molecule *molecule = node->molecule;
120  // Parameters *parameters = node->parameters;
121  const Vector *coords = node->coords;
122  int numAtoms = molecule->numAtoms;
123 
124  if (objc == 2) {
125  // get all the coordinates
126  for (int i=0; i<numAtoms; i++) {
127  Tcl_Obj *newlist = Tcl_NewListObj(0, NULL);
128  Tcl_Obj *arrkey = Tcl_NewIntObj(i+1);
129  Tcl_IncrRefCount(arrkey);
130  Tcl_ListObjAppendElement(interp, newlist,
131  Tcl_NewDoubleObj(coords[i].x));
132  Tcl_ListObjAppendElement(interp, newlist,
133  Tcl_NewDoubleObj(coords[i].y));
134  Tcl_ListObjAppendElement(interp, newlist,
135  Tcl_NewDoubleObj(coords[i].z));
136  if (!Tcl_ObjSetVar2(interp, vname, arrkey, newlist, 0))
137  return TCL_ERROR;
138  Tcl_DecrRefCount(arrkey);
139  }
140  } else {
141  // third argument must be a list of indices
142  int nelems;
143  Tcl_Obj **elems;
144  if (Tcl_ListObjGetElements(interp, objv[2], &nelems, &elems) != TCL_OK) {
145  return TCL_ERROR;
146  }
147  for (int i=0; i<nelems; i++) {
148  int ind;
149  if (Tcl_GetIntFromObj(interp, elems[i], &ind) != TCL_OK)
150  return TCL_ERROR;
151  Tcl_Obj *newlist = Tcl_NewListObj(0, NULL);
152  Tcl_Obj *arrkey = Tcl_NewIntObj(ind);
153  Tcl_IncrRefCount(arrkey);
154  --ind;
155  Tcl_ListObjAppendElement(interp, newlist,
156  Tcl_NewDoubleObj(coords[ind].x));
157  Tcl_ListObjAppendElement(interp, newlist,
158  Tcl_NewDoubleObj(coords[ind].y));
159  Tcl_ListObjAppendElement(interp, newlist,
160  Tcl_NewDoubleObj(coords[ind].z));
161  if (!Tcl_ObjSetVar2(interp, vname, arrkey, newlist, 0))
162  return TCL_ERROR;
163  Tcl_DecrRefCount(arrkey);
164  }
165  }
166  return TCL_OK;
167 }
static Node * Object()
Definition: Node.h:86
Definition: Node.h:78
Definition: Vector.h:64
gridSize z
int numAtoms
Definition: Molecule.h:557
Vector * coords
Definition: Node.h:185
gridSize y
gridSize x
Molecule * molecule
Definition: Node.h:176
static float * coords
Definition: ScriptTcl.C:66
static int Tcl_radiusOfGyration ( ClientData  ,
Tcl_Interp *  interp,
int  argc,
const 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().

79  {
80 
81  Node *node = Node::Object();
82  Molecule *molecule = node->molecule;
83  // Parameters *parameters = node->parameters;
84  Vector *coordinates = node->coords;
85  int numAtoms = molecule->numAtoms;
86 
87  Vector center = 0;
88  BigReal totalMass = 0;
89  int i;
90  for( i = 0; i < numAtoms; ++i ) {
91  BigReal mass = molecule->atommass(i);
92  totalMass += mass;
93  center += mass * coordinates[i];
94  }
95  center /= totalMass;
96 
97  BigReal moment = 0;
98  for( i = 0; i < numAtoms; ++i ) {
99  BigReal mass = molecule->atommass(i);
100  moment += mass * (coordinates[i] - center).length2();
101  }
102  BigReal radius = sqrt(moment/totalMass);
103 
104  char s[1024];
105  sprintf(s,"%g", radius);
106  Tcl_SetResult(interp,s,TCL_VOLATILE);
107 
108  return TCL_OK;
109 }
static Node * Object()
Definition: Node.h:86
Definition: Node.h:78
Definition: Vector.h:64
int numAtoms
Definition: Molecule.h:557
Vector * coords
Definition: Node.h:185
Real atommass(int anum) const
Definition: Molecule.h:1042
Molecule * molecule
Definition: Node.h:176
double BigReal
Definition: common.h:114