int main () { //PDBFile pdb ("quartz_100_short.pdb"); PDBFile pdb ("beta-cristobalite.pdb"); // create the quartz unitcell Molecule * uc = pdb.Molecules(0); //make copies of the quartz unitcell and shift them around //VecR x_shift (4.91, 0.0, 0.0); VecR x_shift (10.0, 0.0, 0.0); VecR y_shift (0.0, 10.0, 0.0); VecR z_shift (0.0, 0.0, 0.0); // Create the slab by creating and shifting copies of the unit cell Mol_ptr_vec mols = UnitCellToSlab(uc, x_shift, y_shift, z_shift); Molecule * mol = MakeSingleMolecule (mols); //AddDanglingHydrogens (mol); // Take care of renaming the atoms and the residue before printing it out FixSingleMoleculeNaming (mol); PrintMoleculePDB (mol); return 0; }
int main () { PDBFile pdb ("temp.pdb"); Molecule * mol = pdb.Molecules(0); mol->Name("qtz"); std::vector<Atom *> atoms = mol->Atoms(); /* cycle through each atom in order of the pdb file */ RUN (atoms) { Atom * atom = atoms[i]; atom->Residue("qtz"); VecR pos = atom->Position(); /* find the surface Oxygens */ if (atom->Name().find("O") != string::npos && pos[z] > -7.9) { /* add H's to the surface */ Atom * h = new Atom ("H", pos + VecR (0.0, 0.0, 1.1)); mol->AddAtom(h); } } std::vector<Molecule *> mols; mols.push_back(mol); PDBFile::WritePDB(mols); }
static void dumpStreamData(ScopedPrinter &P, PDBFile &File) { uint32_t StreamCount = File.getNumStreams(); StringRef DumpStreamStr = opts::DumpStreamData; uint32_t DumpStreamNum; if (DumpStreamStr.getAsInteger(/*Radix=*/0U, DumpStreamNum) || DumpStreamNum >= StreamCount) return; uint32_t StreamBytesRead = 0; uint32_t StreamSize = File.getStreamByteSize(DumpStreamNum); auto StreamBlocks = File.getStreamBlockList(DumpStreamNum); for (uint32_t StreamBlockAddr : StreamBlocks) { uint32_t BytesLeftToReadInStream = StreamSize - StreamBytesRead; if (BytesLeftToReadInStream == 0) break; uint32_t BytesToReadInBlock = std::min( BytesLeftToReadInStream, static_cast<uint32_t>(File.getBlockSize())); auto StreamBlockData = File.getBlockData(StreamBlockAddr, BytesToReadInBlock); outs() << StreamBlockData; StreamBytesRead += StreamBlockData.size(); } }
static bool diffAndPrint(StringRef Label, PDBFile &File1, PDBFile &File2, T V1, T V2) { if (V1 == V2) { outs() << formatv(" {0}: No differences detected!\n", Label); return false; } outs().indent(2) << Label << "\n"; outs().indent(4) << formatv("{0}: {1}\n", File1.getFilePath(), V1); outs().indent(4) << formatv("{0}: {1}\n", File2.getFilePath(), V2); return true; }
static void dumpStreamSizes(ScopedPrinter &P, PDBFile &File) { if (!opts::DumpStreamSizes) return; ListScope L(P, "StreamSizes"); uint32_t StreamCount = File.getNumStreams(); for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) { std::string Name("Stream "); Name += to_string(StreamIdx); P.printNumber(Name, File.getStreamByteSize(StreamIdx)); } }
static void dumpStreamBlocks(ScopedPrinter &P, PDBFile &File) { if (!opts::DumpStreamBlocks) return; ListScope L(P, "StreamBlocks"); uint32_t StreamCount = File.getNumStreams(); for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) { std::string Name("Stream "); Name += to_string(StreamIdx); auto StreamBlocks = File.getStreamBlockList(StreamIdx); P.printList(Name, StreamBlocks); } }
static bool diffAndPrint(StringRef Label, PDBFile &File1, PDBFile &File2, ArrayRef<T> V1, ArrayRef<T> V2) { if (V1 == V2) { outs() << formatv(" {0}: No differences detected!\n", Label); return false; } outs().indent(2) << Label << "\n"; outs().indent(4) << formatv("{0}: {1}\n", File1.getFilePath(), make_range(V1.begin(), V1.end())); outs().indent(4) << formatv("{0}: {1}\n", File2.getFilePath(), make_range(V2.begin(), V2.end())); return true; }
static void dumpNamedStream(ScopedPrinter &P, PDBFile &File, StringRef Stream) { InfoStream &IS = File.getPDBInfoStream(); uint32_t NameStreamIndex = IS.getNamedStreamIndex(Stream); if (NameStreamIndex != 0) { std::string Name("Stream '"); Name += Stream; Name += "'"; DictScope D(P, Name); P.printNumber("Index", NameStreamIndex); MappedBlockStream NameStream(NameStreamIndex, File); StreamReader Reader(NameStream); NameHashTable NameTable; NameTable.load(Reader); P.printHex("Signature", NameTable.getSignature()); P.printNumber("Version", NameTable.getHashVersion()); P.printNumber("Name Count", NameTable.getNameCount()); ListScope L(P, "Names"); for (uint32_t ID : NameTable.name_ids()) { StringRef Str = NameTable.getStringForID(ID); if (!Str.empty()) P.printString(Str); } } }
static void dumpInfoStream(ScopedPrinter &P, PDBFile &File) { InfoStream &IS = File.getPDBInfoStream(); DictScope D(P, "PDB Stream"); P.printNumber("Version", IS.getVersion()); P.printHex("Signature", IS.getSignature()); P.printNumber("Age", IS.getAge()); P.printObject("Guid", IS.getGuid()); }
static void dumpFileHeaders(ScopedPrinter &P, PDBFile &File) { if (!opts::DumpHeaders) return; DictScope D(P, "FileHeaders"); P.printNumber("BlockSize", File.getBlockSize()); P.printNumber("Unknown0", File.getUnknown0()); P.printNumber("NumBlocks", File.getBlockCount()); P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes()); P.printNumber("Unknown1", File.getUnknown1()); P.printNumber("BlockMapAddr", File.getBlockMapIndex()); P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks()); P.printNumber("BlockMapOffset", File.getBlockMapOffset()); // The directory is not contiguous. Instead, the block map contains a // contiguous list of block numbers whose contents, when concatenated in // order, make up the directory. P.printList("DirectoryBlocks", File.getDirectoryBlockArray()); P.printNumber("NumStreams", File.getNumStreams()); }
static bool printSymmetricDifferences(PDBFile &File1, PDBFile &File2, T &&OnlyRange1, T &&OnlyRange2, StringRef Label) { bool HasDiff = false; if (!OnlyRange1.empty()) { HasDiff = true; outs() << formatv(" {0} {1}(s) only in ({2})\n", OnlyRange1.size(), Label, File1.getFilePath()); for (const auto &Item : OnlyRange1) outs() << formatv(" {0}\n", Label, Item); } if (!OnlyRange2.empty()) { HasDiff = true; outs() << formatv(" {0} {1}(s) only in ({2})\n", OnlyRange2.size(), File2.getFilePath()); for (const auto &Item : OnlyRange2) outs() << formatv(" {0}\n", Item); } return HasDiff; }
int main () { // The unitcell's PDB file - must have a "TER" after the residue PDBFile pdb ("octadecane.pdb"); string name = "odn"; double spacing = 5.528; // inter-chain spacing GridParams params (pdb.Molecules(0), name, spacing, 7, 1, 6); // Create the slab by creating and shifting copies of the unit cell Mol_ptr_vec mols = UnitCellToSlab(params); //Molecule * mol = MakeSingleMolecule (params); //AddDanglingHydrogens (params); // Take care of renaming the atoms and the residue before printing it out //FixSingleMoleculeNaming (params); PrintMoleculesPDB (mols); return 0; }
int main () { PDBFile pdb ("octadecane.pdb"); //MDSystem::Dimensions(VecR(29.868, 100.0, 27.792)); Atom_ptr_vec& atoms = pdb.Atoms(); printf ("!entry.xxx.unit.connectivity table int atom1x int atom2x int flags\n"); /* cycle through each atom in order of the pdb file */ for (int i = 0; i != atoms.size() - 1; i++) { for (int j = i+1; j != atoms.size(); j++) { //double distance = MDSystem::Distance(atoms[i],atoms[j]).Magnitude(); double distance = (atoms[i]->Position() - atoms[j]->Position()).Magnitude(); if (distance < 1.7) { printf (" %d %d 1\n", i+1, j+1); } } } return 0; }
static void dumpDbiStream(ScopedPrinter &P, PDBFile &File) { DbiStream &DS = File.getPDBDbiStream(); DictScope D(P, "DBI Stream"); P.printNumber("Dbi Version", DS.getDbiVersion()); P.printNumber("Age", DS.getAge()); P.printBoolean("Incremental Linking", DS.isIncrementallyLinked()); P.printBoolean("Has CTypes", DS.hasCTypes()); P.printBoolean("Is Stripped", DS.isStripped()); P.printObject("Machine Type", DS.getMachineType()); P.printNumber("Number of Symbols", DS.getNumberOfSymbols()); uint16_t Major = DS.getBuildMajorVersion(); uint16_t Minor = DS.getBuildMinorVersion(); P.printVersion("Toolchain Version", Major, Minor); std::string DllName; raw_string_ostream DllStream(DllName); DllStream << "mspdb" << Major << Minor << ".dll version"; DllStream.flush(); P.printVersion(DllName, Major, Minor, DS.getPdbDllVersion()); ListScope L(P, "Modules"); for (auto &Modi : DS.modules()) { DictScope DD(P); P.printString("Name", Modi.Info.getModuleName()); P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex()); P.printString("Object File Name", Modi.Info.getObjFileName()); P.printNumber("Num Files", Modi.Info.getNumberOfFiles()); P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex()); P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex()); P.printNumber("Line Info Byte Size", Modi.Info.getLineInfoByteSize()); P.printNumber("C13 Line Info Byte Size", Modi.Info.getC13LineInfoByteSize()); P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize()); P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex()); P.printBoolean("Has EC Info", Modi.Info.hasECInfo()); std::string FileListName = to_string(Modi.SourceFiles.size()) + " Contributing Source Files"; ListScope LL(P, FileListName); for (auto File : Modi.SourceFiles) P.printString(File); } }
static void dumpTpiStream(ScopedPrinter &P, PDBFile &File) { if (!opts::DumpTypeStream) return; DictScope D(P, "Type Info Stream"); TpiStream &Tpi = File.getPDBTpiStream(); P.printNumber("TPI Version", Tpi.getTpiVersion()); P.printNumber("Record count", Tpi.NumTypeRecords()); if (!opts::DumpTpiRecordBytes) return; ListScope L(P, "Records"); for (auto &Type : Tpi.types()) { DictScope DD(P, ""); P.printHex("Kind", unsigned(Type.Leaf)); P.printBinaryBlock("Bytes", Type.LeafData); } }
Expected<std::unique_ptr<DbiStream>> DbiStreamBuilder::build(PDBFile &File, const msf::WritableStream &Buffer) { if (!VerHeader.hasValue()) return make_error<RawError>(raw_error_code::unspecified, "Missing DBI Stream Version"); if (auto EC = finalize()) return std::move(EC); auto StreamData = MappedBlockStream::createIndexedStream(File.getMsfLayout(), Buffer, StreamDBI); auto Dbi = llvm::make_unique<DbiStream>(File, std::move(StreamData)); Dbi->Header = Header; Dbi->FileInfoSubstream = ReadableStreamRef(FileInfoBuffer); Dbi->ModInfoSubstream = ReadableStreamRef(ModInfoBuffer); if (auto EC = Dbi->initializeModInfoArray()) return std::move(EC); if (auto EC = Dbi->initializeFileInfo()) return std::move(EC); return std::move(Dbi); }
Expected<std::unique_ptr<TpiStream>> TpiStreamBuilder::build(PDBFile &File, const msf::WritableStream &Buffer) { if (!VerHeader.hasValue()) return make_error<RawError>(raw_error_code::unspecified, "Missing TPI Stream Version"); if (auto EC = finalize()) return std::move(EC); auto StreamData = MappedBlockStream::createIndexedStream(File.getMsfLayout(), Buffer, Idx); auto Tpi = llvm::make_unique<TpiStream>(File, std::move(StreamData)); Tpi->Header = Header; Tpi->TypeRecords = VarStreamArray<codeview::CVType>(TypeRecordStream); if (HashValueStream) { Tpi->HashStream = std::move(HashValueStream); StreamReader HSR(*Tpi->HashStream); if (auto EC = HSR.readArray(Tpi->HashValues, TypeRecords.size())) return std::move(EC); } return std::move(Tpi); }
YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()), Obj(File.getAllocator()) {}
int main(int argc, char** argv) { if (argc != 3) { Log << "Usage:" << argv[0] << " <PDB infile> <PDB outfile> [<amber parameter file>]" << endl; return 1; } System system; PDBFile f; f.open(argv[1]); if (f.bad()) { Log.error() << "cannot read PDB file " << argv[1] << endl; return 2; } f >> system; f.close(); FragmentDB db(""); // ResidueChecker check(db); // system.apply(check); db.normalize_names.setNamingStandard("Amber"); system.apply(db.normalize_names); system.apply(db.build_bonds); Size cyx_counter = 0; Size hip_counter = 0; ResidueIterator it = system.beginResidue(); for (; +it; ++it) { if (it->getFullName() == "CYS-S") { it->setName("CYX"); cyx_counter++; } if (it->getFullName() == "HIS") { it->setName("HIP"); hip_counter++; } } if (cyx_counter > 0) { Log.info() << "Renamed " << cyx_counter << " residues from CYS-S to CYX" << endl; } if (hip_counter > 0) { Log.info() << "Renamed " << hip_counter << " residues from HIS to HIP" << endl; } PDBFile g; g.open(argv[2], ios::out); if (g.bad()) { Log.error() << "cannot write PDB file " << argv[2] << endl; return 2; } g << system; g.close(); Log.info() << endl << "Conversion to AMBER naming scheme done. Please note that you might" << endl << "have to edit the resulting file by hand (if there are HIS or CYS" << endl << "residues in the original file, e. g.)" << endl << endl << "Good luck." << endl; }
int main (int argc, char **argv) { // instantiate CommandlineParser object supplying // - tool name // - short description // - version string // - build date // - category CommandlineParser parpars("DockPoseClustering", "clusters docking poses ", VERSION, String(__DATE__), "Docking"); // we register an input file parameter // - CLI switch // - description // - Inputfile parpars.registerMandatoryInputFile("i_pdb", "input pdb-file"); parpars.registerOptionalInputFile("i_dcd", "input dcd-file"); ///TODO: offer the alternatives in a more elegant way! parpars.registerOptionalInputFile("i_trans", "or input transformation file for rigid rmsd clustering "); // we register an output file parameter // - CLI switch // - description // - parameter type // - required // - default value // - hidden in galaxy parpars.registerMandatoryOutputFile("o_index_list", "output file name for the index list "); parpars.setParameterAsHidden("o_index_list"); parpars.registerOptionalOutputFile("o_score_matrix", "output file name for scoring matrix "); parpars.setParameterAsHidden("o_score_matrix"); parpars.registerOptionalOutputFile("o_dcd", "output file name for the first cluster dcd file "); parpars.setParameterAsHidden("o_dcd"); parpars.registerOptionalGalaxyOutputId("o_dcd_id", "output id ", "$o_dcd.id"); // need to be hidden in command line mode parpars.setParameterAsAdvanced("o_dcd_id"); parpars.setParameterAsHidden("o_dcd_id"); parpars.registerOptionalGalaxyOutputFolder("o_dcd_dir", "output directory for 2nd to last cluster dcd file (if needed) ", "$__new_file_path__"); // need to be hidden in command line mode parpars.setParameterAsAdvanced("o_dcd_dir"); parpars.setParameterAsHidden("o_dcd_dir"); // register String parameter for supplying minimal rmsd between clusters parpars.registerOptionalDoubleParameter("rmsd_cutoff", "minimal rmsd between the final clusters (default 5.0) ", 5.0); parpars.setParameterRestrictions("rmsd_cutoff", 0, 100); // choice of cluster algorithm parpars.registerOptionalStringParameter("alg", "algorithm used for clustering (CLINK_DEFAYS, CLINK_ALTHAUS, NEAREST_NEIGHBOR_CHAIN_WARD, SLINK_SIBSON, TRIVIAL_COMPLETE_LINKAGE) ", "CLINK_DEFAYS"); list<String> cluster_algs; cluster_algs.push_back("CLINK_DEFAYS"); cluster_algs.push_back("CLINK_ALTHAUS"); cluster_algs.push_back("TRIVIAL_COMPLETE_LINKAGE"); cluster_algs.push_back("NEAREST_NEIGHBOR_CHAIN_WARD"); cluster_algs.push_back("SLINK_SIBSON"); parpars.setParameterRestrictions("alg", cluster_algs); // choice of atom rmsd scope parpars.registerOptionalStringParameter("scope", "atoms to be considered for scoreing a pose (C_ALPHA, BACKBONE, ALL_ATOMS) ", "C_ALPHA"); list<String> rmsd_levels; rmsd_levels.push_back("C_ALPHA"); //rmsd_levels.push_back("HEAVY_ATOMS"); //TODO rmsd_levels.push_back("BACKBONE"); rmsd_levels.push_back("ALL_ATOMS"); parpars.setParameterRestrictions("scope", rmsd_levels); // choice of rmsd type parpars.registerOptionalStringParameter("rmsd_type", "rmsd type used for clustering (SNAPSHOT_RMSD, RIGID_RMSD, CENTER_OF_MASS_DISTANCE) ", "SNAPSHOT_RMSD"); list<String> rmsd_types; rmsd_types.push_back("SNAPSHOT_RMSD"); rmsd_types.push_back("RIGID_RMSD"); rmsd_types.push_back("CENTER_OF_MASS_DISTANCE"); parpars.setParameterRestrictions("rmsd_type", rmsd_types); // further optional output parameters parpars.registerOptionalOutputFile("o_red_dcd", "output file for the reduced cluster set (dcd with one structure per final cluster) "); // write the final cluster tree in boost::serialize format, if it was computed parpars.registerOptionalOutputFile("o_cluster_tree", "output file containing the cluster tree in boost::serialize format (if the tree was computed) "); // register bool parameter for using pre-clustering parpars.registerFlag("use_refinement", "Apply a second clustering run with different options (-refine_alg <string>, -refine_rmsd_type <string>, and -refine_rmsd_scope <string>)", false, true); // refinement algorithm parpars.registerOptionalStringParameter("refine_alg", "algorithm used for second clustering run (CLINK_DEFAYS, NEAREST_NEIGHBOR_CHAIN_WARD, SLINK_SIBSON, TRIVIAL_COMPLETE_LINKAGE) ", "CLINK_DEFAYS"); parpars.setParameterAsHidden("refine_alg"); parpars.setParameterRestrictions("refine_alg", cluster_algs); // refinement rmsd type parpars.registerOptionalStringParameter("refine_rmsd_type", "rmsd type used for second clustering run (SNAPSHOT_RMSD, RIGID_RMSD, CENTER_OF_MASS_DISTANCE) ", "SNAPSHOT_RMSD"); parpars.setParameterAsHidden("refine_rmsd_type"); parpars.setParameterRestrictions("refine_rmsd_type", rmsd_types); // refinement rmsd scope parpars.registerOptionalStringParameter("refine_rmsd_scope", "atoms to be considered for rmsd score in second clustering run (C_ALPHA, BACKBONE, ALL_ATOMS) ", "C_ALPHA"); parpars.setParameterAsHidden("refine_rmsd_scope"); parpars.setParameterRestrictions("refine_rmsd_scope", rmsd_levels); // force serial execution, even if the algorithm supports parallel runs parpars.registerFlag("run_serial", "force serial excecution, even if parallel execution would be supported by the algorithm", false, true); // the manual String man = "This tool computes clusters of docking poses given as conformation set or a list of rigid transformations.\n\nParameters are either the input ConformationSet (-i_dcd) and one corresponding pdb file (-i_pdb), or a transformation file (-i_trans). Output can be a cluster index list (-o_index_list), a cluster scoring matrix (-o_score_matrix), or dcd files per cluster (-o_dcd). Optional parameters are the algorithm (-alg), the minimal rmsd between the final clusters (-rmsd_cutoff), the rmsd type (-rmsd_type), and the type of atoms used for scoring a pose (-scope). The optional parameter -o_red_dcd sets the output file for the reduced cluster set (one representative per cluster). The optional parameter -o_cluster_tree specifies the output file for storing the cluster tree.\n\nOutput of this tool depends in the choice of the output parameters."; parpars.setToolManual(man); // here we set the types of I/O files parpars.setSupportedFormats("i_dcd","dcd"); parpars.setSupportedFormats("i_pdb","pdb"); parpars.setSupportedFormats("i_trans","txt"); parpars.setSupportedFormats("o_index_list","txt"); parpars.setSupportedFormats("o_score_matrix","txt"); parpars.setSupportedFormats("o_dcd","dcd"); parpars.setSupportedFormats("o_red_dcd","dcd"); parpars.setSupportedFormats("o_cluster_tree","dat"); parpars.parse(argc, argv); ////////////////////////////////////////////////// if (parpars.has("o_dcd")) { if (!parpars.has("o_dcd_dir") || !parpars.has("o_dcd_id")) { Log << "Output type \"dcd\" requires setting the options \"o_dir\" \"o_id\"! Abort!" << endl; return 1; } } if ( parpars.has("o_cluster_tree") && (!parpars.has("alg") || parpars.get("alg") != "NEAREST_NEIGHBOR_CHAIN_WARD")) { Log << "Output of cluster tree requires Ward algorithm! Abort!" << endl; return 1; } // read the input PDBFile pdb; pdb.open(parpars.get("i_pdb")); System sys; pdb.read(sys); ConformationSet cs; cs.setup(sys); if (parpars.has("i_dcd")) { cs.readDCDFile(parpars.get("i_dcd")); } cs.resetScoring(); PoseClustering pc; if (parpars.has("i_trans")) { pc.setBaseSystemAndTransformations(sys, parpars.get("i_trans")); } if (parpars.has("rmsd_cutoff")) { float rmsd = parpars.get("rmsd_cutoff").toInt(); pc.options.setReal(PoseClustering::Option::DISTANCE_THRESHOLD, rmsd); } if (parpars.has("scope")) { String scope = parpars.get("scope"); if (scope == "C_ALPHA") pc.options.set(PoseClustering::Option::RMSD_LEVEL_OF_DETAIL, PoseClustering::C_ALPHA); else if (scope == "BACKBONE") pc.options.set(PoseClustering::Option::RMSD_LEVEL_OF_DETAIL, PoseClustering::BACKBONE); else if (scope == "ALL_ATOMS") pc.options.set(PoseClustering::Option::RMSD_LEVEL_OF_DETAIL, PoseClustering::ALL_ATOMS); else Log.info() << "Unknown value " << scope << " for option scope." << endl; } if (parpars.has("alg")) { String alg = parpars.get("alg"); if (alg == "CLINK_DEFAYS") pc.options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::CLINK_DEFAYS); else if (alg == "CLINK_ALTHAUS") pc.options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::CLINK_ALTHAUS); else if (alg == "SLINK_SIBSON") pc.options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::SLINK_SIBSON); else if (alg == "TRIVIAL_COMPLETE_LINKAGE") pc.options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::TRIVIAL_COMPLETE_LINKAGE); else if (alg == "NEAREST_NEIGHBOR_CHAIN_WARD") pc.options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::NEAREST_NEIGHBOR_CHAIN_WARD); else Log.info() << "Unknown value " << alg << " for option alg." << endl; } if (parpars.has("rmsd_type")) { String type = parpars.get("rmsd_type"); if (type == "SNAPSHOT_RMSD") pc.options.set(PoseClustering::Option::RMSD_TYPE, PoseClustering::SNAPSHOT_RMSD); else if (type == "RIGID_RMSD") pc.options.set(PoseClustering::Option::RMSD_TYPE, PoseClustering::RIGID_RMSD); else if (type == "CENTER_OF_MASS_DISTANCE") { pc.options.set(PoseClustering::Option::RMSD_TYPE, PoseClustering::CENTER_OF_MASS_DISTANCE); Log << "Parameter scope will be ignored!" << endl; } else Log.info() << "Unknown value " << type << " for option rmsd_type." << endl; } if (parpars.has("run_serial")) { pc.options.set(PoseClustering::Option::RUN_PARALLEL, false); } else { pc.options.set(PoseClustering::Option::RUN_PARALLEL, true); } if (parpars.has("i_dcd")) { pc.setConformationSet(&cs); } pc.compute(); // do we need a second clustering run? if (parpars.has("use_refinement")) { // get the options Options refine_options = pc.options; if (parpars.has("refine_rmsd_scope")) { String scope = parpars.get("refine_rmsd_scope"); if (scope == "C_ALPHA") refine_options.set(PoseClustering::Option::RMSD_LEVEL_OF_DETAIL, PoseClustering::C_ALPHA); else if (scope == "BACKBONE") refine_options.set(PoseClustering::Option::RMSD_LEVEL_OF_DETAIL, PoseClustering::BACKBONE); else if (scope == "ALL_ATOMS") refine_options.set(PoseClustering::Option::RMSD_LEVEL_OF_DETAIL, PoseClustering::ALL_ATOMS); else Log.info() << "Unknown value " << scope << " for option refine_rmsd_scope." << endl; } if (parpars.has("refine_alg")) { String alg = parpars.get("refine_alg"); if (alg == "CLINK_DEFAYS") refine_options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::CLINK_DEFAYS); else if (alg == "CLINK_ALTHAUS") refine_options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::CLINK_ALTHAUS); else if (alg == "SLINK_SIBSON") refine_options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::SLINK_SIBSON); else if (alg == "TRIVIAL_COMPLETE_LINKAGE") refine_options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::TRIVIAL_COMPLETE_LINKAGE); else if (alg == "NEAREST_NEIGHBOR_CHAIN_WARD") refine_options.set(PoseClustering::Option::CLUSTER_METHOD, PoseClustering::NEAREST_NEIGHBOR_CHAIN_WARD); else Log.info() << "Unknown value " << alg << " for option refine_alg." << endl; } if (parpars.has("refine_rmsd_type")) { String type = parpars.get("refine_rmsd_type"); if (type == "SNAPSHOT_RMSD") refine_options.set(PoseClustering::Option::RMSD_TYPE, PoseClustering::SNAPSHOT_RMSD); else if (type == "RIGID_RMSD") refine_options.set(PoseClustering::Option::RMSD_TYPE, PoseClustering::RIGID_RMSD); else if (type == "CENTER_OF_MASS_DISTANCE") { refine_options.set(PoseClustering::Option::RMSD_TYPE, PoseClustering::CENTER_OF_MASS_DISTANCE); Log << "Parameter scope will be ignored!" << endl; } else Log.info() << "Unknown value " << type << " for option refine_rmsd_type." << endl; } pc.refineClustering(refine_options); } Size num_clusters = pc.getNumberOfClusters(); Log << "Computed " << num_clusters << " clusters, start writing..." << endl; if (parpars.has("o_dcd")) { for (Size i = 0; i < num_clusters; i++) { Log << " Cluster " << i << " has " << pc.getClusterSize(i) << " members." << endl; boost::shared_ptr<ConformationSet> new_cs = pc.getClusterConformationSet(i); String outfile_name = (i == 0) ? String(parpars.get("o_dcd")) : String(parpars.get("o_dcd_dir")) + "/primary_" + String(parpars.get("o_dcd_id")) + "_cluster" + String(i) + "_visible_dcd"; //Log << " Writing solution " << String(i) << " as " << outfile_name << endl; new_cs->writeDCDFile(outfile_name); } } if (parpars.has("o_index_list")) { String outfile_name = String(parpars.get("o_index_list")); File cluster_outfile(outfile_name, std::ios::out); pc.printClusters(cluster_outfile); } if (parpars.has("o_score_matrix")) { String outfile_name = String(parpars.get("o_score_matrix")); File cluster_outfile(outfile_name, std::ios::out); pc.printClusterScores(cluster_outfile); } // print pc.printClusters(); pc.printClusterScores(); if (parpars.has("o_cluster_tree")) { File cluster_out(parpars.get("o_cluster_tree"), std::ios::out); pc.serializeWardClusterTree(cluster_out, true); cluster_out.close(); } if (parpars.has("o_red_dcd")) { String outfile_name = String(parpars.get("o_red_dcd")); boost::shared_ptr<ConformationSet> cs = pc.getReducedConformationSet(); cs->writeDCDFile(outfile_name); } Log << "done." << endl; return 0; }
int main(int argc, char* argv[]) { FDPB fdpb; // instantiate CommandlineParser object CommandlineParser parpars("CalculateSolvationFreeEnergy", "calculate solvation free energy of a protein using AMBER ", VERSION, String(__DATE__), "ForceFields"); parpars.registerParameter("pdb", "input pdb file ", INFILE, true); parpars.registerParameter("epsilon_medium", "dielectric constant in medium", DOUBLE, false, fdpb.options.getReal(FDPB::Option::SOLVENT_DC)); parpars.registerParameter("epsilon_vacuum", "dielectric constant in vacuum", DOUBLE, false, 1); // the manual String man = String("This tool computes the solvation free energy of a pdb file using the Jackson-Sternberg approach (bonded energy using a force field and a non bonded energy (electrostatics only) by solving the Poisson-Boltzmann equation. Parameters are the dielectric constants for the medium (-epsilon_medium) and the vacuum (-epsilon_vacuum)."); parpars.setToolManual(man); parpars.setSupportedFormats("pdb", "pdb"); // parse the command line parpars.parse(argc, argv); PDBFile pdb; pdb.open(parpars.get("pdb"), std::ios::in); if (!pdb) { // if file does not exist: complain and abort Log.error() << "error opening " << parpars.get("pdb") << " for input." << std::endl; exit(2); } System sys; pdb >> sys; pdb.close(); // normalize the names and build all bonds FragmentDB db(""); sys.apply(db.normalize_names); sys.apply(db.build_bonds); // TODO: Ask ResidueChecker if everything is ok! see tool CalculateEnergy // create an AMBER force field without non-bonded interactions AmberFF FF(sys); // calculate the total energy float total_energy = FF.updateEnergy(); //Log << FF.getResults() << std::endl; //Log << " total energy using force field evaluation: " << total_energy << " kJ/mol" << std::endl; //Log << "removing non bonded energy terms ..." << std::endl; FF.removeComponent("Amber NonBonded"); // calculate the internal energy (neglecting internal VdW interactions) float internal_energy = FF.updateEnergy(); //Log << FF.getResults() << std::endl; Log << " internal energy: " << internal_energy << " kJ/mol" << std::endl; // assign atom radii AssignRadiusProcessor radius_processor("radii/PARSE.siz"); sys.apply(radius_processor); // calculate the electrostatic part of the solvation energy //FDPB fdpb; float dielectric_const = fdpb.options.getReal(FDPB::Option::SOLVENT_DC); if (parpars.has("epsilon_medium")) dielectric_const = parpars.get("epsilon_medium").toFloat(); fdpb.options[FDPB::Option::SOLVENT_DC] = dielectric_const; Log << "... using dielectric constant in medium: " << fdpb.options[FDPB::Option::SOLVENT_DC].toFloat() << std::endl; fdpb.setup(sys); fdpb.solve(); float solvent_energy = fdpb.getEnergy(); dielectric_const = 1.0; if (parpars.has("epsilon_vacuum")) dielectric_const = parpars.get("epsilon_vacuum").toFloat(); fdpb.options[FDPB::Option::SOLVENT_DC] = dielectric_const; Log << "... using dielectric constant in vacuum: " << fdpb.options[FDPB::Option::SOLVENT_DC].toFloat() << std::endl; fdpb.setup(sys); fdpb.solve(); float vacuum_energy = fdpb.getEnergy(); Log << "\n electrostatic solvation free energy: " << solvent_energy - vacuum_energy << std::endl; Log << "\n total energy using a combination of force field and FDPB evaluation: " << internal_energy - vacuum_energy + solvent_energy << " kJ/mol" << std::endl; return 0; }
int main(int argc, char* argv[]) { // instantiate CommandlineParser object CommandlineParser parpars("CalculateEnergy", "calculate free energy of a protein ", VERSION, String(__DATE__), "ForceFields"); parpars.registerMandatoryInputFile("pdb", "input pdb file "); // TODO: offer upload of a distinguished fragDB file? // choice of force field parpars.registerOptionalStringParameter("force_field", "force field (AMBER, MMFF94)", "AMBER"); list<String> force_fields; force_fields.push_back("AMBER"); force_fields.push_back("MMFF94"); // TODO: shall we offer CHARM as well? parpars.setParameterRestrictions("force_field", force_fields); // TODO: shall we offer a force field parameter file upload? // TODO: check the naming! parpars.registerOptionalDoubleParameter("non_bond_cutoff", "cutoff radius in calculations of nonbonded interactions", 20.0); parpars.registerOptionalDoubleParameter("elec_stat_cuton", "electrostatic cuton", 13.0); parpars.registerOptionalDoubleParameter("elec_stat_cutoff", "electrostatic cutoff", 15.0); parpars.registerFlag("dist_dep_dielec", "apply distance dependent dielectric constant", false); // NOTE: assign is the default //parpars.registerFlag("assign_typenames","automatically assign type names to the system", false); //parpars.registerFlag("assign_types","automatically assign types to the system if missing", false); //parpars.registerFlag("assign_charges", "automatically assign charges to the system if missing", false); // TODO: if we only allow PDBFile to upload then from where do we get stuff to overwrite?? parpars.registerFlag("overwrite_types", "overwrite even non-empty type names", false); parpars.registerFlag("overwrite_charges","overwrite even non-zero charges", false); // the manual String man = String("This tool computes the free energy of a pdb file using a specified force field (-force_field) and force field parameters (-non_bond_cutoff, -elec_stat_cuton ... )."); parpars.setToolManual(man); parpars.setSupportedFormats("pdb", "pdb"); // parse the command line parpars.parse(argc, argv); PDBFile pdb; pdb.open(parpars.get("pdb"), std::ios::in); if (!pdb) { // if file does not exist: complain and abort Log.error() << "error opening " << parpars.get("pdb") << " for input." << std::endl; exit(2); } System sys; pdb >> sys; pdb.close(); // normalize the names and build all bonds FragmentDB db(""); sys.apply(db.normalize_names); sys.apply(db.build_bonds); // check the structure Log.info() << " checking residues..." << std::endl; ResidueChecker rc(db); sys.apply(rc); if (!rc.getStatus()) { Log.error() << "There are errors in the given structure. Use the ResidueChecker tool for further investigation." << std::endl; exit(2); } // create a force field AmberFF* amber_force_field = NULL; MMFF94* mmff_force_field = NULL; ForceField* force_field = NULL; if (parpars.has("force_field")) { String penalty_table = parpars.get("force_field"); if (penalty_table == "AMBER") { amber_force_field = new AmberFF(); force_field = amber_force_field; Log << " using the amber force field" << std::endl; } else if (penalty_table == "MMFF94") { mmff_force_field = new MMFF94(); force_field = mmff_force_field; Log << " using the MMFF94 force field" << std::endl; } else { Log.error() << "Unknown force field " << parpars.get("force_field") << " Abort." << std::endl; exit(2); } } if (!amber_force_field && !mmff_force_field) { Log.error() << "Invalid force field. Abort." << std::endl; exit(2); } // set the ff options according the parameters float non_bonded_cutoff = 0; if (parpars.has("non_bond_cutoff")) { non_bonded_cutoff = parpars.get("non_bond_cutoff").toFloat(); if (amber_force_field) { //TODO: something wents awfully wrong with the FF default options! // cout << "non_bond_cutoff " << amber_force_field->options.getReal(AmberFF::Option::NONBONDED_CUTOFF) << " "<< amber_force_field->options.getReal(AmberFF::Default::NONBONDED_CUTOFF) << endl; amber_force_field->options[AmberFF::Option::NONBONDED_CUTOFF] = non_bonded_cutoff; } else if (mmff_force_field) { mmff_force_field->options[MMFF94::Option::NONBONDED_CUTOFF] = non_bonded_cutoff; } Log << " used non bonded cutoff: " << non_bonded_cutoff << std::endl; } float elec_stat_cuton = 0; if (parpars.has("elec_stat_cuton")) { elec_stat_cuton = parpars.get("elec_stat_cuton").toFloat(); if (amber_force_field) { // cout << "elec_stat_cuton" << force_field->options[AmberFF::Option::ELECTROSTATIC_CUTON] << endl; amber_force_field->options[AmberFF::Option::ELECTROSTATIC_CUTON] = elec_stat_cuton; } else if (mmff_force_field) { // cout << "elec_stat_cuton" << force_field->options[MMFF94::Option::ELECTROSTATIC_CUTON] << endl; mmff_force_field->options[MMFF94::Option::ELECTROSTATIC_CUTON] = elec_stat_cuton; } Log << " used electrostatic cuton: " << elec_stat_cuton << std::endl; } float elec_stat_cutoff = 0; if (parpars.has("elec_stat_cutoff")) { elec_stat_cutoff = parpars.get("elec_stat_cutoff").toFloat(); if (amber_force_field) { amber_force_field->options[AmberFF::Option::ELECTROSTATIC_CUTOFF] = elec_stat_cutoff; } else if (mmff_force_field) { mmff_force_field->options[MMFF94::Option::ELECTROSTATIC_CUTOFF] = elec_stat_cutoff; } Log << " used electrostatic cutoff: " << elec_stat_cutoff << std::endl; } bool dist_dep_dielectric = true; if (parpars.has("dist_dep_dielec")) { dist_dep_dielectric = parpars.get("dist_dep_dielec").toBool(); if (amber_force_field) { amber_force_field->options[AmberFF::Option::DISTANCE_DEPENDENT_DIELECTRIC] = dist_dep_dielectric; } else if (mmff_force_field) { mmff_force_field->options[MMFF94::Option::DISTANCE_DEPENDENT_DIELECTRIC] = dist_dep_dielectric; } } Log << " distance dependent dielectric constant " << (dist_dep_dielectric ? "on" : "off") << std::endl; // we handle ASSIGN_TYPES and ASSIGN_TYPENAMES together bool assign_types = true; if (parpars.has("assign_types")) { assign_types = parpars.get("assign_types").toBool(); if (amber_force_field) { amber_force_field->options[AmberFF::Option::ASSIGN_TYPENAMES] = assign_types; amber_force_field->options[AmberFF::Option::ASSIGN_TYPES] = assign_types; } else if (mmff_force_field) { mmff_force_field->options[MMFF94::Option::ASSIGN_TYPENAMES] = assign_types; mmff_force_field->options[MMFF94::Option::ASSIGN_TYPES] = assign_types; } } Log << " assignment of missing types " << (assign_types ? "on" : "off") << std::endl; bool overwrite_types = true; if (parpars.has("overwrite_types")) { overwrite_types = parpars.get("overwrite_types").toBool(); if (amber_force_field) { amber_force_field->options[AmberFF::Option::OVERWRITE_TYPENAMES] = overwrite_types; } else if (mmff_force_field) { mmff_force_field->options[MMFF94::Option::OVERWRITE_TYPENAMES] = overwrite_types; } } Log << " overwrite types " << (overwrite_types ? "on" : "off") << std::endl; bool assign_charges = true; if (parpars.has("assign_charges")) { assign_charges = parpars.get("assign_charges").toBool(); if (amber_force_field) { amber_force_field->options[AmberFF::Option::ASSIGN_CHARGES] = assign_charges; } else if (mmff_force_field) { mmff_force_field->options[MMFF94::Option::ASSIGN_CHARGES] = assign_charges; } } Log << " assignment of missing charges " << (assign_charges ? "on" : "off") << std::endl; bool overwrite_charges = true; if (parpars.has("overwrite_charges")) { overwrite_charges = parpars.get("overwrite_charges").toBool(); if (amber_force_field) { amber_force_field->options[AmberFF::Option::OVERWRITE_CHARGES] = overwrite_charges; } else if (mmff_force_field) { mmff_force_field->options[MMFF94::Option::OVERWRITE_CHARGES] = overwrite_charges; } } Log << " overwrite charges " << (overwrite_charges ? "on" : "off") << std::endl; // setup the force field Log.info() << " setting up the force field..." << endl; force_field->setup(sys); // setup successful? if ( (force_field->getUnassignedAtoms().size() > 0) || !force_field->isValid()) { Log.error() << "There are parameterless atoms in the structure. Use the ResidueChecker tool for further investigation." << std::endl; exit(2); } // trigger the energy computations force_field->updateEnergy(); // print the result Log.info() << force_field->getResults() << endl; return 0; }
int main(int argc, char** argv) { CommandlineParser parpars("PoseIndices2PDB", "converts pose indices into PDB files ", VERSION, String(__DATE__), "Convert, combine and store"); parpars.registerMandatoryInputFile("i_clust", "input cluster index file"); parpars.registerMandatoryInputFile("i_trans", "input tranformation file"); parpars.registerMandatoryInputFile("i_pdb", "input reference pdb file"); parpars.registerMandatoryOutputFile("o", "output file name prefix for resulting pdb files"); parpars.setParameterAsHidden("o"); // parameters for galaxy for handling multiple output files parpars.registerOptionalGalaxyOutputId("o_id", "output file name prefix for 2nd to last pdb file", "$o.id"); // need to be hidden in command line mode parpars.setParameterAsHidden("o_id"); parpars.setParameterAsAdvanced("o_id"); // parameters for galaxy for handling multiple output files parpars.registerOptionalGalaxyOutputFolder("o_dir", "output directory for 2nd to last pdb file", "$__new_file_path__"); // need to be hidden in command line mode parpars.setParameterAsHidden("o_dir"); parpars.setParameterAsAdvanced("o_dir"); // the manual String man = "This tool converts all pose indices from a given transformation file and the corresponding reference PDBFile into separate PDBFiles.\n\nParameters are the input pose index file (-i_clust), the original transformation file (-i_trans), the corresponding reference pdb file (-i_pdb) and a naming schema for the resulting pdb files (-o). \n\nOutput of this tool is a set of PDBFiles representing the docking poses belonging to the given input cluster."; parpars.setToolManual(man); // here we set the types of I/O files parpars.setSupportedFormats("i_clust","txt"); parpars.setSupportedFormats("i_trans","dcd"); parpars.setSupportedFormats("i_pdb","pdb"); parpars.setSupportedFormats("o","pdb"); parpars.parse(argc, argv); ////////////////////////////////////////////////// // read the input PDBFile pdb; pdb.open(parpars.get("i_pdb")); System sys; pdb.read(sys); PoseClustering pc; if (parpars.has("i_trans")) { pc.options.set(PoseClustering::Option::RMSD_TYPE, PoseClustering::RIGID_RMSD); pc.setBaseSystemAndTransformations(sys, parpars.get("i_trans")); } //std::vector< std::set<Index> > clusters; LineBasedFile file(parpars.get("i_clust"), std::ios::in); vector<String> fields; String cluster_id = -1; String pose_id = -1; // called as command line or e.g. via galaxy? bool is_cmd = !parpars.has("env") || ((parpars.has("env") && parpars.get("env")=="cmdline")); bool first_sol = true; while (file.LineBasedFile::readLine()) { // get the line String current_cluster = file.getLine(); if (current_cluster.getField(1) == "cluster") { cluster_id = current_cluster.getField(2); pose_id = -1; if (file.LineBasedFile::readLine()) { current_cluster = file.getLine(); fields.clear(); current_cluster.split(fields); for (Size i=0; i < fields.size(); i++) { System new_pose_sys(sys); pose_id = fields[i]; pc.applyTransformation2System(pose_id.toInt(), new_pose_sys); // create the output name String outfile_name = String(parpars.get("o")) + "_clust_" + cluster_id + "_pose_" + String(pose_id) + ".pdb"; if (parpars.has("o_dir") && is_cmd && (parpars.get("o_dir") != "$__new_file_path__")) { outfile_name = String(parpars.get("o_dir")) + "/" + outfile_name; } // NOTE: Galaxy requires this strange naming convention // including the fact, that zero-th element has a different name if (!is_cmd) { outfile_name = (first_sol) ? String(parpars.get("o")) : String(parpars.get("o_dir")) + "/primary_" + String(parpars.get("o_id")) + "_clust_" + cluster_id + "_pose_" + String(pose_id) + "_visible_pdb"; } PDBFile file(outfile_name, ios::out); if (file.bad()) { Log.error() << "cannot write file " << outfile_name << endl; return 2; } file << new_pose_sys; file.close(); // needed for galaxy output if (first_sol) first_sol = false; Log << "wrote file " << outfile_name << endl; } } } } Log << "done." << endl; return 0; }