LOOS  v2.3.2
spring_functions.cpp
1 /*
2  Spring Functions from Elastic Network Tools in LOOS
3  (c) 2010 Tod D. Romo, Grossfield Lab, URMC
4 */
5 
6 
7 #include "spring_functions.hpp"
8 
9 namespace ENM {
10 
11  std::vector<std::string> splitCommaSeparatedList(const std::string& s){
12  std::vector<std::string> holder;
13  std::string::size_type prev =s.find_first_not_of(",", 0);
14  std::string::size_type pos = s.find_first_of(",", prev);
15 
16  while (pos != std::string::npos || prev != std::string::npos){
17  holder.push_back(s.substr(prev, pos-prev));
18  prev = s.find_first_not_of(",", pos);
19  pos = s.find_first_of(",", prev);
20  }
21 
22  return(holder);
23  }
24 
25 
26 
36  SpringFunction* springFactory(const std::string& spring_desc) {
37 
38  std::vector<std::string> list = splitCommaSeparatedList(spring_desc);
39  SpringFunction *spring = 0;
40 
41  if (list[0] == "distance")
42  spring = new DistanceCutoff;
43  else if (list[0] == "weighted")
44  spring = new DistanceWeight;
45  else if (list[0] == "exponential")
46  spring = new ExponentialDistance;
47  else if (list[0] == "hca" || spring_desc == "HCA")
48  spring = new HCA;
49  else if (list[0] == "constant")
50  spring = new ConstBonded;
51  else
52  throw(BadSpringFunction("Bad Spring Function Name"));
53 
54  if (list.size() > 1) {
55  if (list.size() < spring->paramSize())
56  throw(BadSpringParameter("Too few spring parameters"));
57 
58  std::vector<double> params;
59 
60  for (uint i=1; i <= spring->paramSize(); ++i)
61  params.push_back(loos::parseStringAs<double>(list.at(i)));
62 
63  spring->setParams(params);
64  if (!spring->validParams())
65  throw(BadSpringParameter("Bad Spring Parameter"));
66  }
67 
68  return(spring);
69  }
70 
71 
72 
73  // Returns a list of names for spring functions. Needs to match
74  // what's checked for above...
75 
76  std::vector<std::string> springNames() {
77  std::vector<std::string> names;
78 
79  names.push_back("distance");
80  names.push_back("weighted");
81  names.push_back("exponential");
82  names.push_back("hca");
83 
84  return(names);
85  }
86 
87 
88 };
virtual Params setParams(const Params &konst)=0
Sets the internal constants, returning the unused ones.
Use a spring function that is a constant weight regardless of distance.
Distance weighting (i.e. )
Unspecified problem with parameters in SpringFunction.
Interface for ENM spring functions.
SpringFunction * springFactory(const std::string &spring_desc)
Factory function for generating new SpringFunction instances based on a user string.
Namespace to encapsulate Elastic Network Model routines.
Definition: anm-lib.hpp:32
HCA method (bimodal distance-based function)
std::vector< std::string > springNames()
List of possible names for springFactory()
virtual uint paramSize() const =0
How many internal constants there are.
Basic distance cutoff for "traditional" ENM.
Bad spring function was requested.
virtual bool validParams() const =0
Determines if the internal constants are "valid".
Exponential distance weighting (i.e. )