Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

GeometrySpring.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: GeometrySpring.C,v $
00013  *      $Author: johns $        $Locker:  $                $State: Exp $
00014  *      $Revision: 1.19 $      $Date: 2019/01/17 21:20:59 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * Simulates and draws a spring between two atoms in IMD.
00020  *
00021  ***************************************************************************/
00022 
00023 #include <stdio.h>
00024 
00025 #include "GeometrySpring.h"
00026 #include "MoleculeList.h"
00027 #include "Molecule.h"
00028 #include "utilities.h"
00029 
00030 
00032 GeometrySpring::GeometrySpring(int *m, int *a, MoleculeList
00033                                *mlist,CommandQueue *cq, float thek, Displayable *d)
00034         : GeometryMol(2, m, a, NULL, mlist, cq, d) {
00035   k = thek;
00036   rvec[0]=0;
00037   rvec[1]=0;
00038   rvec[2]=0;
00039 }
00040 
00041 
00042 
00044 
00045 // recalculate the value of this geometry, and return it
00046 float GeometrySpring::calculate(void) {
00047 
00048   // get coords to calculate distance 
00049   float pos1[3], pos2[3];
00050   if(!normal_atom_coord(0, pos1))
00051     return 0.0;
00052   if(!normal_atom_coord(1, pos2))
00053     return 0.0;
00054 
00055   vec_sub(pos2, pos2, pos1);
00056 
00057   // XXX this is a hack
00058   // decaying average for smooth springs
00059   vec_scale(rvec,0.95f,rvec);
00060   vec_scale(pos2,0.05f,pos2);
00061   vec_add(rvec,rvec,pos2);
00062   geomValue = norm(rvec);
00063 
00064   return(geomValue);
00065 }
00066 
00067 void GeometrySpring::prepare() {
00068   // get the molecules and atoms
00069   int mol1 = objIndex[0];
00070   int mol2 = objIndex[1];
00071   int atom1 = comIndex[0];
00072   int atom2 = comIndex[1];
00073   Molecule *m1 = molList->mol_from_id(mol1);
00074   Molecule *m2 = molList->mol_from_id(mol2);
00075 
00076   // find the appropriate force between these two
00077   float force1[3],force2[3];
00078   vec_scale(force1,k,rvec);
00079   vec_scale(force2,-k,rvec);
00080   
00081   // apply it to the atoms
00082   m1->addForce(atom1,force1);
00083   m2->addForce(atom2,force2);
00084 }
00085 
00086 // draw the geometry marker in the given Displayable's drawing list
00087 void GeometrySpring::create_cmd_list() {
00088   char valbuf[32];
00089 
00090   // get the transformed positions, and draw a line between them
00091   reset_disp_list();
00092   float pos1[3], pos2[3];
00093   if(!transformed_atom_coord(0, pos1))
00094     return;
00095   if(!transformed_atom_coord(1, pos2))
00096     return;
00097 
00098   // draw a line into the given Displayable
00099   display_line(pos1, pos2, cmdList);
00100   
00101   // print value of distance at midpoint
00102   midpoint(valuePos, pos1, pos2);
00103   // left-align the value so that it doesn't appear to shift its position
00104   // when the label text size changes.  Shift it to the right by a constant
00105   // amount so that it doesn't intersect the line.
00106   valuePos[0] += 0.05f;
00107   sprintf(valbuf, "-%7.2f", geomValue);
00108   display_string(valbuf, cmdList);
00109 
00110 }
00111 
00112 void GeometrySpring::set_pick(void) {
00113 
00114   // set the Tcl values
00115   if(objIndex[0] == objIndex[1]) {  // selections must be from the same molid
00116     set_pick_selection(objIndex[0], 2, comIndex);
00117   } else {
00118     set_pick_selection();  // if bad, set to the "nothing" molecule
00119   }
00120   set_pick_value(geomValue);
00121 }
00122 
00123 GeometrySpring::~GeometrySpring() {
00124 }

Generated on Fri Mar 29 02:45:17 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002