std::string _test_ifile(TextInput a) { std::string read; while (true) { std::string cur; a.get_stream() >> cur; if (!a) break; read = read + cur; } std::cout << read; return read; }
Hierarchy read_mol2(TextInput mol2_file, Model* model, Mol2Selector* mol2sel) { if (!mol2sel) { mol2sel = new AllMol2Selector(); } IMP::PointerMember<Mol2Selector> sel(mol2sel); // create a map to save atom_index and atom particle pairs boost::unordered_map<Int, Particle*> molecule_atoms; // create root particle Hierarchy root_d = root_particle(model, mol2_file.get_name()); std::string line; Hierarchy molecule_d; while (std::getline(mol2_file.get_stream(), line)) { // check the line is the title line @<TRIPOS>MOLECULE if (internal::is_MOLECULE_rec(line)) { molecule_atoms.clear(); molecule_d = read_molecule_mol2(model, mol2_file, root_d); } // check the starting line of atom block @<TRIPOS>ATOM else if (internal::is_MOL2ATOM_rec(line)) { if (!molecule_d) { IMP_THROW("Atom seen before molecule on line " << line, IOException); } read_atom_mol2(model, mol2_file, molecule_d, molecule_atoms, mol2sel); } // check the starting line of bond block @<TRIPOS>BOND else if (internal::is_BOND_rec(line)) { read_bond_mol2(model, mol2_file, molecule_d, molecule_atoms); } else { IMP_LOG_TERSE("Couldn't parse line " << line << std::endl); } } // Hierarchies mps = get_by_type(root_d, RESIDUE_TYPE); // std::cout << "check " << mps.size() << std::endl; add_radii(root_d); IMP_INTERNAL_CHECK(root_d.get_is_valid(true), "Invalid hierarchy produced"); return root_d; }
void CHARMMParameters::read_parameter_file(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"); } }
void CHARMMParameters::read_topology_file(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); } }