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

SpringTool.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 #include "SpringTool.h"
00010 #include "Matrix4.h"
00011 #include "utilities.h"
00012 #include "Molecule.h"
00013 #include "VMDApp.h"
00014 #include "PickList.h"
00015 #include "MoleculeList.h"
00016 
00017 SpringTool::SpringTool(int id, VMDApp *vmdapp, Displayable *disp) 
00018 : Tool(id, vmdapp, disp) {
00019   offset[0]=offset[1]=offset[2]=0;
00020   tugging=0;
00021   springscale = 1.0;
00022 }
00023 
00024 
00025 static int get_nearby_atom(VMDApp *app, const float *pos,
00026              int *molret, int *atomret) {
00027   int mol = -1;
00028   int atom = -1;
00029   int tag; 
00030   
00031   Pickable *p;
00032   if (app->display) {
00033     // pick a nearby atom
00034     p = app->pickList->pick_check(3, pos, tag, NULL, 0.2f);
00035 
00036     if (p) {
00037       Molecule *m = app->moleculeList->check_pickable(p);
00038       if (m) {
00039         mol = m->id();
00040         atom = tag;
00041       }
00042     }
00043   }
00044 
00045   if (atom == -1 || mol == -1) return 0;
00046   *molret = mol;
00047   *atomret = atom;
00048   return 1;
00049 }
00050 
00051 
00052 void SpringTool::do_event() {
00053   // always update!
00054   tool_location_update();
00055 
00056   if (istugging()) {  // Tugging is enabled...
00057     if (!tugging || !is_targeted()) { // but we're not tugging now
00058       if (!target(TARGET_TUG, tugged_pos, 0)) {
00059         // Didn't pick anything, so return
00060         tugging = 0;
00061         return;
00062       }
00063 
00064       tugging = 1;
00065       // We're starting the force field, so set the offset
00066       vec_sub(offset, Tool::position(), tugged_pos);
00067       start_tug();
00068     }
00069     target(TARGET_TUG, tugged_pos, 1);
00070     // Apply the force field...
00071     float offset_tugged_pos[3]; // offset+tugged_pos
00072     vec_add(offset_tugged_pos,offset,tugged_pos);
00073     set_tug_constraint(offset_tugged_pos);
00074     
00075     float diff[3];
00076     vec_sub(diff, Tool::position(), offset_tugged_pos);
00077     // diff now is in my units, but we should do it in mol units
00078     vec_scale(diff, dtool->scale/getTargetScale(), diff);
00079     // scale by the force scaling spring constant
00080     vec_scale(diff, forcescale, diff); 
00081     do_tug(diff);
00082   } else if (tugging) { // Tugging has been disabled
00083     int mol1=-1, mol2=-1;
00084     int atom1=-1, atom2=-1;
00085     int ret1 = get_nearby_atom(app, position(), &mol1, &atom1);
00086     int ret2 = get_targeted_atom(&mol2, &atom2);
00087 
00088     if (ret1 && ret2) { // got two atoms successfully
00089       if (mol1 == mol2) { // on the same molecule
00090         if (atom1 != atom2) { // two *different* atoms
00091           int atombuf[2];
00092           int molbuf[2];
00093           atombuf[0] = atom1; atombuf[1] = atom2;
00094           molbuf[0] = mol1; molbuf[1] = mol2;
00095           app->label_add("Springs", 2, molbuf, atombuf, NULL, 0.0f, 1);
00096         }       
00097       }
00098     }
00099 
00100     // now let go
00101     let_go();
00102     tugging = 0;
00103     forceoff();
00104     offset[0]=offset[1]=offset[2]=0;
00105   } 
00106 }
00107 
00108 
00109 void SpringTool::set_tug_constraint(float *newpos) {
00110   setconstraint(50, newpos);
00111   sendforce();
00112 }
00113 
00114 
00115 void SpringTool::do_tug(float *force) {
00116   tug(force);
00117 }
00118 

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