00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
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 
00046 float GeometrySpring::calculate(void) {
00047 
00048   
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   
00058   
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   
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   
00077   float force1[3],force2[3];
00078   vec_scale(force1,k,rvec);
00079   vec_scale(force2,-k,rvec);
00080   
00081   
00082   m1->addForce(atom1,force1);
00083   m2->addForce(atom2,force2);
00084 }
00085 
00086 
00087 void GeometrySpring::create_cmd_list() {
00088   char valbuf[32];
00089 
00090   
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   
00099   display_line(pos1, pos2, cmdList);
00100   
00101   
00102   midpoint(valuePos, pos1, pos2);
00103   
00104   
00105   
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   
00115   if(objIndex[0] == objIndex[1]) {  
00116     set_pick_selection(objIndex[0], 2, comIndex);
00117   } else {
00118     set_pick_selection();  
00119   }
00120   set_pick_value(geomValue);
00121 }
00122 
00123 GeometrySpring::~GeometrySpring() {
00124 }