Exemplo n.º 1
0
 void setMembers(const std::vector<int>& members) {
   members_ = members;
   if (members_.size() < 3 || members_.size() > 4) {
     std::ostringstream oss;
     oss << "members" << containerToString(members) << " is invalid" << 
       std::endl;
     throw OpenMDException(oss.str());
   }
 }        
Exemplo n.º 2
0
    void addSatellite(int sat) {
      if (satellites_.size() > 3) {
        std::ostringstream oss;
        oss << "Too many satellites in inversion to add another!" << std::endl;
        throw OpenMDException(oss.str());
      } else {
	satellites_.push_back(sat);
      }
    }
Exemplo n.º 3
0
 virtual void validate() {
   ParamMap::iterator i;
   for (i = parameters_.begin(); i != parameters_.end(); ++i) {
     if (!i->second->isOptional() && i->second->empty()) {
       std::stringstream ss;
       ss <<  i->second->getKeyword()  << " must be set.\n";
       throw OpenMDException(ss.str());
     }
   }
 }
Exemplo n.º 4
0
 void assign(const std::string& keyword, T val) {
   ParamMap::iterator i =parameters_.find(keyword);
   if (i != parameters_.end()) {
     bool result = i->second->setData(val);
     if (!result ) {
       std::stringstream ss;
       ss <<   "Error in parsing " << keyword << ": expected " << 
         i->second->getParamType() << " but got " << val << "\n";
       throw OpenMDException(ss.str());
     }
   } else if (deprecatedKeywords_.find(keyword) != 
              deprecatedKeywords_.end()){
     std::cout << keyword << 
       " has been deprecated in OpenMD.  Please update your .md file.\n";
   } else {
     std::stringstream ss;
     ss << keyword << " is not a recognized keyword.\n";
     throw OpenMDException(ss.str());
   }
 }
Exemplo n.º 5
0
    void setSatellites(const std::vector<int> &sats) {
      if (sats.size() == 3) {
	satellites_.push_back(sats.at(0));
	satellites_.push_back(sats.at(1));
	satellites_.push_back(sats.at(2));
      } else {
        std::ostringstream oss;
        oss << "Incorrect number of satellites to add to inversion!" << std::endl;
        throw OpenMDException(oss.str());
      }
    }
Exemplo n.º 6
0
  TorsionType* TorsionTypeParser::parseLine(const std::string& line) {
    
    StringTokenizer tokenizer(line);
    TorsionType* torsionType = NULL;
    int nTokens = tokenizer.countTokens();

    if (nTokens < 1) {
      throw OpenMDException("TorsionTypeParser: Not enough tokens");
    }
    
    TorsionTypeEnum tt = getTorsionTypeEnum(tokenizer.nextToken());

    nTokens -= 1;

    switch(tt) {

    case ttGhostTorsion:
      if (nTokens < 4) {
        throw OpenMDException("TorsionTypeParser: Not enough tokens");
      } else {
        
	RealType k3 = tokenizer.nextTokenAsDouble();
	RealType k2 = tokenizer.nextTokenAsDouble();
	RealType k1 = tokenizer.nextTokenAsDouble();
	RealType k0 = tokenizer.nextTokenAsDouble();
        
        if (trans180_)
          torsionType = new CubicTorsionType( k3, k2,  k1, k0);
        else 
          torsionType = new CubicTorsionType(-k3, k2, -k1, k0);
      }
      break;
            
    case ttCubic :
      if (nTokens < 4) {
        throw OpenMDException("TorsionTypeParser: Not enough tokens");
      } else {

	RealType k3 = tokenizer.nextTokenAsDouble();
	RealType k2 = tokenizer.nextTokenAsDouble();
	RealType k1 = tokenizer.nextTokenAsDouble();
	RealType k0 = tokenizer.nextTokenAsDouble();
                
        if (trans180_)
          torsionType = new CubicTorsionType( k3, k2,  k1, k0);
        else 
          torsionType = new CubicTorsionType(-k3, k2, -k1, k0);
      }
      break;
            
    case ttQuartic:
      if (nTokens < 5) {
        throw OpenMDException("TorsionTypeParser: Not enough tokens");
      } else {

	RealType k4 = tokenizer.nextTokenAsDouble();
	RealType k3 = tokenizer.nextTokenAsDouble();
	RealType k2 = tokenizer.nextTokenAsDouble();
	RealType k1 = tokenizer.nextTokenAsDouble();
	RealType k0 = tokenizer.nextTokenAsDouble();
                
        if (trans180_)
          torsionType = new QuarticTorsionType( k4,  k3, k2,  k1, k0);
        else 
          torsionType = new QuarticTorsionType( k4, -k3, k2, -k1, k0);
      }
      break;
        
    case ttPolynomial:
      if (nTokens < 2 || nTokens % 2 != 0) {
        throw OpenMDException("TorsionTypeParser: Not enough tokens");
      } else {
	int nPairs = nTokens / 2;
	int power;
	RealType coefficient;
	torsionType = new PolynomialTorsionType();

        PolynomialTorsionType* ptt = dynamic_cast<PolynomialTorsionType*>(torsionType); 
                
	for (int i = 0; i < nPairs; ++i) {
	  power = tokenizer.nextTokenAsInt();
          bool isOdd = power % 2 == 0 ? false : true;

	  coefficient = tokenizer.nextTokenAsDouble();

          if (!trans180_ && isOdd)
            coefficient = -coefficient;

          ptt->setCoefficient(power, coefficient);
          
	}
      }
            
      break;
             
    case ttCharmm:
            
      if (nTokens < 3 || nTokens % 3 != 0) {
        throw OpenMDException("TorsionTypeParser: Not enough tokens");
      } else {
	int nSets = nTokens / 3;
  
        std::vector<CharmmTorsionParameter> parameters;             
	for (int i = 0; i < nSets; ++i) {
          CharmmTorsionParameter currParam;
	  currParam.kchi = tokenizer.nextTokenAsDouble();
	  currParam.n = tokenizer.nextTokenAsInt();
	  currParam.delta = tokenizer.nextTokenAsDouble() / 180.0 * NumericConstant::PI; //convert to rad

          bool isOdd = currParam.n % 2 == 0 ? false : true;
          if (!trans180_) {           
            currParam.delta = NumericConstant::PI - currParam.delta;
            if (isOdd) currParam.kchi = -currParam.kchi;
          }

          parameters.push_back(currParam);
	}

	torsionType = new CharmmTorsionType(parameters);

      }

      break;

    case ttOpls:
            
      if (nTokens < 3) {
        throw OpenMDException("TorsionTypeParser: Not enough tokens");
      } else {
	RealType v1 = tokenizer.nextTokenAsDouble();
	RealType v2 = tokenizer.nextTokenAsDouble();
	RealType v3 = tokenizer.nextTokenAsDouble();
        
	torsionType = new OplsTorsionType(v1, v2, v3, trans180_);
      }

      break;
            

    case ttTrappe:
            
      if (nTokens < 4) {
        throw OpenMDException("TorsionTypeParser: Not enough tokens");
      } else {

	RealType c0 = tokenizer.nextTokenAsDouble();
	RealType c1 = tokenizer.nextTokenAsDouble();
	RealType c2 = tokenizer.nextTokenAsDouble();
	RealType c3 = tokenizer.nextTokenAsDouble();
	torsionType = new TrappeTorsionType(c0, c1, c2, c3, trans180_);
      }

      break;

    case ttHarmonic:
            
      if (nTokens < 2) {
        throw OpenMDException("TorsionTypeParser: Not enough tokens");
      } else {
        // Most torsions don't have specific angle information since
        // they are cosine polynomials.  This one is different,
        // however.  To match our other force field files
        // (particularly for bends): 
        //
        // phi0 should be read in degrees
        // d0 should be read in kcal / mol / degrees^2

        RealType degreesPerRadian = 180.0 / NumericConstant::PI;

        // convert to radians
	RealType phi0 = tokenizer.nextTokenAsDouble() / degreesPerRadian;
        
        // convert to kcal / mol / radians^2
	RealType d0 = tokenizer.nextTokenAsDouble() * pow(degreesPerRadian,2);

        if (!trans180_)
          phi0 = NumericConstant::PI - phi0;

	torsionType = new HarmonicTorsionType(d0, phi0);
      }

      break;
            
    case ttUnknown :
    default:
      throw OpenMDException("TorsionTypeParser: Unknown Torsion Type");
    }
    return torsionType;
  }