コード例 #1
0
ファイル: CHARMMParameters.cpp プロジェクト: apolitis/imp
ResidueType CHARMMParameters::parse_residue_line(const String &line,
                                                 bool translate_names_to_pdb) {
  Strings split_results;
  boost::split(split_results, line, boost::is_any_of(" \t"),
               boost::token_compress_on);
  if (split_results.size() < 3) {
    IMP_THROW("Invalid RESI line: " << line, ValueException);
  }
  String curr_residue =
      get_residue_name(split_results[1], translate_names_to_pdb);
  if (ResidueType::get_key_exists(curr_residue)) {
    return ResidueType(curr_residue);
  } else {
    // assume charmm is correct
    return ResidueType(ResidueType::add_key(curr_residue));
  }
}
コード例 #2
0
void CHARMMParameters::read_topology_file(base::TextInput input_file,
                                          bool translate_names_to_pdb)
{
  IMP_OBJECT_LOG;
  const String MASS_LINE = "MASS";
  const String DEFA_LINE = "DEFA";
  const String PATC_LINE = "PATC";
  const String RESI_LINE = "RESI";
  const String PRES_LINE = "PRES";
  const String ATOM_LINE = "ATOM";
  const String DELE_LINE = "DELE";
  const String BOND_LINE = "BOND";
  const String BOND_LINE2 = "DOUBLE";
  const String ANGLE_LINE = "ANGL";
  const String ANGLE_LINE2 = "THET";
  const String DIHEDRAL_LINE = "DIHE";
  const String DIHEDRAL_LINE2 = "PHI";
  const String IMPROPER_LINE = "IMPR";
  const String IMPROPER_LINE2 = "IMPH";
  const String IC_LINE = "IC";
  std::string first_patch = "", last_patch = "";
  Pointer<CHARMMIdealResidueTopology> residue;
  Pointer<CHARMMPatch> patch;

  ResidueType curr_res_type;
  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;

    // read residue line
    if(line.substr(0, RESI_LINE.length()) == RESI_LINE) {
      if (residue) {
        add_residue_topology(residue.release());
      } else if (patch) {
        add_patch(patch.release());
      }
      curr_res_type = parse_residue_line(line, translate_names_to_pdb);
      ResidueType rt(curr_res_type.get_string());
      residue = new CHARMMIdealResidueTopology(rt);
      residue->set_default_first_patch(first_patch);
      residue->set_default_last_patch(last_patch);

    // handle patch residues
    } else if (line.substr(0, PRES_LINE.length()) == PRES_LINE) {
      if (residue) {
        add_residue_topology(residue.release());
      } else if (patch) {
        add_patch(patch.release());
      }
      Strings split_results;
      boost::split(split_results, line, boost::is_any_of(" \t"),
                   boost::token_compress_on);
      if (split_results.size() < 3) {
        IMP_THROW("Invalid PRES line: " << line, ValueException);
      }
      patch = new CHARMMPatch(get_residue_name(split_results[1],
                                               translate_names_to_pdb));

    // handle MASS line
    } else if (line.substr(0, MASS_LINE.length()) == MASS_LINE) {
      parse_mass_line(line, atom_type_to_element_);

    // handle DEFA line
    } else if (line.substr(0, DEFA_LINE.length()) == DEFA_LINE) {
      parse_patch_line(line, first_patch, last_patch, translate_names_to_pdb);

    // handle PATC line
    } else if (line.substr(0, PATC_LINE.length()) == PATC_LINE
               && residue) {
      std::string first = residue->get_default_first_patch();
      std::string last = residue->get_default_last_patch();
      parse_patch_line(line, first, last, translate_names_to_pdb);
      residue->set_default_first_patch(first);
      residue->set_default_last_patch(last);

    // read DELE line
    } else if (line.substr(0, DELE_LINE.length()) == DELE_LINE
               && patch) {
      parse_dele_line(line, patch, translate_names_to_pdb);

    // read atom line
    } else if (line.substr(0, ATOM_LINE.length()) == ATOM_LINE
               && (residue || patch)) {
      parse_atom_line(line, curr_res_type, get_residue(residue, patch),
                      translate_names_to_pdb);

    // read bond line
    } else if ((line.substr(0, BOND_LINE.length()) == BOND_LINE ||
               line.substr(0, BOND_LINE2.length()) == BOND_LINE2)
               && (residue || patch)) {
      parse_bond_line(line, curr_res_type, get_residue(residue, patch),
                      translate_names_to_pdb);

    // read angle line
    } else if ((line.substr(0, ANGLE_LINE.length()) == ANGLE_LINE ||
               line.substr(0, ANGLE_LINE2.length()) == ANGLE_LINE2)
               && (residue || patch)) {
      parse_angle_line(line, get_residue(residue, patch),
                       translate_names_to_pdb);
    // read dihedral line
    } else if ((line.substr(0, DIHEDRAL_LINE.length()) == DIHEDRAL_LINE ||
               line.substr(0, DIHEDRAL_LINE2.length()) == DIHEDRAL_LINE2)
               && (residue || patch)) {
      parse_dihedral_line(line, get_residue(residue, patch),
                          translate_names_to_pdb);
    // read improper line
    } else if ((line.substr(0, IMPROPER_LINE.length()) == IMPROPER_LINE ||
               line.substr(0, IMPROPER_LINE2.length()) == IMPROPER_LINE2)
               && (residue || patch)) {
      parse_improper_line(line, get_residue(residue, patch),
                          translate_names_to_pdb);
    // read internal coordinate line
    } else if (line.substr(0, IC_LINE.length()) == IC_LINE
               && (residue || patch)) {
      parse_internal_coordinate_line(line, get_residue(residue, patch),
                                     translate_names_to_pdb);
    }
  }
  if (residue) {
    add_residue_topology(residue);
  } else if (patch) {
    add_patch(patch);
  }
}