/* ligand/find-ligands.cc * * Copyright 2004, 2005, 2006, 2007 The University of York * Author: Paul Emsley * Copyright 2007 The University of Oxford * Copyright 2012, 2014 by Medical Research Council * Author: Paul Emsley * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ // Portability (getopt) gubbins #ifndef _MSC_VER #include // for getopt(3) #endif #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #ifdef __GNU_LIBRARY__ #include "compat/coot-getopt.h" #else #define __GNU_LIBRARY__ #include "compat/coot-getopt.h" #undef __GNU_LIBRARY__ #endif #include #include #include #include "utils/coot-utils.hh" #include "coot-utils/coot-coord-utils.hh" #include "wligand.hh" void do_just_conformers(int n_conformers, const std::string &cif_file_name) { std::cout << "INFO:: do-just-conformers " << cif_file_name << std::endl; // c.f. the ligand_search_make_conformers_internal() in src. // the model will be extracted from the cif file coot::protein_geometry geom; coot::read_refmac_mon_lib_info_t rmit = geom.init_refmac_mon_lib(cif_file_name, 10); if (rmit.n_bonds == 0) { std::cout << "failed to parse cif " << cif_file_name << std::endl; } else { // happy path unsigned int n_threads = coot::get_max_number_of_threads(); ctpl::thread_pool thread_pool(n_threads); std::vector monomer_names = geom.monomer_types(); if (! monomer_names.empty()) { std::string comp_id = monomer_names.back(); int imol_enc = coot::protein_geometry::IMOL_ENC_ANY; std::pair rest = geom.get_monomer_restraints(comp_id, imol_enc); if (rest.first) { try { bool idealize_flag = true; mmdb::Residue *residue_p = geom.get_residue(comp_id, imol_enc, idealize_flag); if (residue_p) { coot::minimol::residue mmres(residue_p); // somewhat clumsy coot::minimol::fragment frag; frag.addresidue(mmres, false); coot::minimol::molecule mmol(frag); coot::wligand wlig; int imol_ligand = -1; bool optim_geom = true; bool fill_vec = true; wlig.install_simple_wiggly_ligands(&geom, mmol, imol_ligand, n_conformers, optim_geom, fill_vec, &thread_pool, n_threads); std::vector conformers = wlig.get_conformers(); std::string file_name_stub = "conformer-" + comp_id + "-"; for (unsigned int i=0; i lig_files; short int use_wiggly_ligand = 0; int wiggly_ligand_n_samples = 30; std::string cif_file_name = ""; std::string fit_frac_str = ""; std::string coot_ligands_script_file_name = "coot-ligands.scm"; float fit_frac = -1.0; // tested for positivity bool set_absolute = 0; std::string absolute_string = ""; bool blobs_mode = false; float map_sampling_factor = 1.5; std::string map_sampling_factor_str; bool just_conformers_flag = false; bool output_files_in_mmcif = false; // These hold the coordinates of a particular position. The // bool is whether they were set in the input or not. Only of // all 3 are set will findligand search in a particular position // (pretty obviously). // std::pair pos_x(0, 0.0), pos_y(0, 0.0), pos_z(0, 0.0); const char *optstr = "i:h:f:p:s:c:w:n:d"; struct option long_options[] = { {"pdbin", 1, 0, 0}, {"hklin", 1, 0, 0}, {"f", 1, 0, 0}, {"phi", 1, 0, 0}, {"sigma", 1, 0, 0}, {"absolute", 1, 0, 0}, {"mmcif", 0, 0, 0}, {"clusters", 1, 0, 0}, {"samples", 1, 0, 0}, {"dictionary", 1, 0, 0}, {"fit-fraction", 1, 0, 0}, {"flexible", 0, 0, 0}, {"script", 0, 0, 0}, {"blobs", 0, 0, 0}, {"just-conformers", 0, 0, 0}, {"sampling-factor", 1, 0, 0}, {"pos-x", 1, 0, 0}, {"pos-y", 1, 0, 0}, {"pos-z", 1, 0, 0}, {0, 0, 0, 0} }; int ch; int option_index = 0; while ( -1 != (ch = coot_getopt_long(argc, argv, optstr, long_options, &option_index))) { switch(ch) { case 0: if (coot_optarg) { // std::cout << "DEBUG:: " << option_index << " " << strlen(coot_optarg) << std::endl; // std::cout << " " << coot_optarg << std::endl; // std::cout << " ch:: " << ch << std::endl; std::string arg_str = long_options[option_index].name; // std::cout << " considering arg_str :" << arg_str << ":\n"; if (arg_str == "pdbin") { pdb_file_name = coot_optarg; n_used_args += 2; } if (arg_str == "pdb") { pdb_file_name = coot_optarg; n_used_args += 2; } if (arg_str == "hklin") { mtz_filename = coot_optarg; n_used_args += 2; } if (arg_str == "f") { f_col = coot_optarg; n_used_args += 2; } if (arg_str == "phi") { phi_col = coot_optarg; n_used_args += 2; } if (arg_str == "sigma") { sigma_str = coot_optarg; n_used_args += 2; } if (arg_str == "absolute") { absolute_string = coot_optarg; set_absolute = 1; n_used_args += 2; } if (arg_str == "clusters") { n_cluster_string = coot_optarg; n_used_args += 2; } if (arg_str == "samples") { wiggly_ligand_n_samples = atoi(coot_optarg); n_used_args += 2; } if (arg_str == "dictionary") { cif_file_name = coot_optarg; n_used_args += 2; } if (arg_str == "sampling-factor") { map_sampling_factor_str = coot_optarg; n_used_args += 2; } if (arg_str == "fit-fraction") { fit_frac_str = coot_optarg; n_used_args += 2; } if (arg_str == "script") { coot_ligands_script_file_name = coot_optarg; n_used_args += 2; } if (arg_str == "pos-x" || arg_str == "pos-y" || arg_str == "pos-z") { try { float v = coot::util::string_to_float(coot_optarg); if (arg_str == "pos-x") pos_x = std::pair (1, v); if (arg_str == "pos-y") pos_y = std::pair (1, v); if (arg_str == "pos-z") pos_z = std::pair (1, v); } catch (const std::runtime_error &rte) { std::cout << "WARNING:: Failed to convert " << arg_str << " to a number" << std::endl; } n_used_args += 2; } } else { // options without arguments: // long argument without parameter: std::string arg_str(long_options[option_index].name); if (arg_str == "flexible") { use_wiggly_ligand = 1; n_used_args += 1; } if (arg_str == "blobs") { blobs_mode = true; std::cout << "set blobs mode " << std::endl; n_used_args++; } if (arg_str == "just-conformers") { just_conformers_flag = true; n_used_args++; } if (arg_str == "mmcif") { output_files_in_mmcif = true; n_used_args++; } } break; case 'i': pdb_file_name = coot_optarg; n_used_args += 2; break; case 'h': mtz_filename = coot_optarg; n_used_args += 2; break; case 'f': f_col = coot_optarg; n_used_args += 2; break; case 'p': phi_col = coot_optarg; n_used_args += 2; break; case 's': sigma_str = coot_optarg; n_used_args += 2; break; case 'c': n_cluster_string = coot_optarg; n_used_args += 2; break; default: std::cout << "default coot_optarg: " << coot_optarg << std::endl; break; } } if (just_conformers_flag) { // the model is in the cif file do_just_conformers(wiggly_ligand_n_samples, cif_file_name); exit(0); } bool do_it = false; if (pdb_file_name.length() == 0) { std::cout << "Missing input PDB file\n"; exit(1); } else { if (mtz_filename.length() == 0) { std::cout << "Missing MTZ file\n"; exit(1); } else { if (f_col.length() == 0) { std::cout << "Missing F column name\n"; exit(1); } else { if (phi_col.length() == 0) { std::cout << "Missing PHI column name\n"; exit(1); } else { if (sigma_str.length() == 0) { sigma_str = "2.0"; } if (n_cluster_string.length() == 0) { n_cluster_string = "10"; } // std::cout << "------------ argc: " << argc << " n_used_args: " // << n_used_args << std::endl; // 20140520 What was I thinking? The last argument // is the one where the ligand pdb file is. Now we // check all the arguments. // // for (int i=n_used_args; i<(argc-1); i++) for (int i=n_used_args; i > big_blobs = wlig.big_blobs(); unsigned int n_big_blobs = big_blobs.size(); if (n_big_blobs) { std::cout << "=============== start blob-table ==========\n"; for (unsigned int i=0; i wiggled_ligands = wlig.install_simple_wiggly_ligands(&geom, mmol, imol_ligand, wiggly_ligand_n_samples, optim_geom, fill_vec, &thread_pool, n_threads); } catch (const std::runtime_error &mess) { std::cout << "Failed to install flexible ligands\n" << mess.what() << std::endl; } } wlig.fit_ligands_to_clusters(10); } } } } } // what are the results? // now add in the solution ligands: int n_clusters = wlig.n_clusters_final(); coot::minimol::molecule m; for (int iclust=0; iclust 12) nlc = 12; // arbitrary limit of max 12 solutions per cluster float tolerance = 20.0; // limit_solutions should be run only after a post-correlation sort. // wlig.limit_solutions(iclust, correl_frac_lim, nlc, tolerance, true); for (unsigned int isol=0; isolWriteCIFASCII(file_name.c_str()); else ligand_mol->WritePDBASCII(file_name.c_str()); } } } } } } return 0; }