Exemple #1
0
void TextWriter::do_set_frame() {
  if (file_name_.empty() /* || file_name_.find("%1%")== std::string::npos*/) {
    IMP_FAILURE("Cannot set frame on writer without %1% being in the name.");
  }
  if (out_ != TextOutput()) {
    do_close();
    out_ = TextOutput();
  }
  open();
}
void CHARMMParameters::read_parameter_file(base::TextInput input_file) {
  IMP_OBJECT_LOG;
  const String BONDS_LINE = "BOND";
  const String ANGLES_LINE = "ANGL";
  const String ANGLES_LINE2 = "THETA";
  const String DIHEDRALS_LINE = "DIHE";
  const String DIHEDRALS_LINE2 = "PHI";
  const String IMPROPER_LINE = "IMPR";
  const String IMPROPER_LINE2 = "IMPHI";
  const String NONBONDED_LINE = "NONB";
  const String NONBONDED_LINE2 = "NBON";
  enum { NONE, BONDS, ANGLES, DIHEDRALS, IMPROPERS, NONBONDED } section = NONE;

  while (!input_file.get_stream().eof()) {
    String line;
    getline(input_file.get_stream(), line);

    boost::trim(line); // remove all spaces
    // skip comments or empty lines
    if (line[0] == '!' || line[0] == '*' || line.length() == 0) continue;

    if (line.substr(0, NONBONDED_LINE.length()) == NONBONDED_LINE
        || line.substr(0, NONBONDED_LINE2.length()) == NONBONDED_LINE2) {
      section = NONBONDED;
      getline(input_file.get_stream(), line); //remove second line of NONBONDED
    } else if (line.substr(0, BONDS_LINE.length()) == BONDS_LINE) {
      section = BONDS;
    } else if (line.substr(0, ANGLES_LINE.length()) == ANGLES_LINE
               || line.substr(0, ANGLES_LINE2.length()) == ANGLES_LINE2) {
      section = ANGLES;
    } else if (line.substr(0, DIHEDRALS_LINE.length()) == DIHEDRALS_LINE
               || line.substr(0, DIHEDRALS_LINE2.length()) == DIHEDRALS_LINE2) {
      section = DIHEDRALS;
    } else if (line.substr(0, IMPROPER_LINE.length()) == IMPROPER_LINE
               || line.substr(0, IMPROPER_LINE2.length()) == IMPROPER_LINE2) {
      section = IMPROPERS;
    } else if (line.substr(0, 5) == "HBOND" || line.substr(0, 5) == "NBFIX") {
      section = NONE;
    } else if (line.substr(0, 3) == "END") {
      break;
    } else {
      switch(section) {
      case BONDS:
        parse_bonds_parameters_line(line);
        break;
      case ANGLES:
        parse_angles_parameters_line(line);
        break;
      case DIHEDRALS:
        parse_dihedrals_parameters_line(line, dihedral_parameters_);
        break;
      case IMPROPERS:
        parse_dihedrals_parameters_line(line, improper_parameters_);
        break;
      case NONBONDED:
        parse_nonbonded_parameters_line(line);
        break;
      default:
        break;
      }
    }
  }
  if(force_field_2_vdW_.size() == 0) {
    IMP_FAILURE("NONBONDED params not found in Charmm parameter file");
  }
}