Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed backend call to validate #81

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 6 additions & 72 deletions src/privateer/cpp/privateer-bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,6 @@ clipper::MMDBfile mfile;
// mfile.read_file( "input.pdb" );
// mfile.import_minimol( mmol );
using namespace emscripten;

extern "C" std::vector<std::string> read_file(const std::string &file, const std::string &name)
{

char *c_data = (char *)file.c_str();
size_t size = file.length();
::gemmi::Structure structure = ::gemmi::read_structure_from_char_array(c_data, size, name);

clipper::GEMMIFile gemmi_file;
clipper::GemmiStructure *gemmi_structure = &gemmi_file;
gemmi_structure->structure_ = structure;

clipper::MiniMol mol;
gemmi_file.import_minimol(mol);

privateer::json::GlobalTorsionZScore torsions_zscore_database = privateer::json::read_json_file_for_torsions_zscore_database("privateer_torsions_z_score_database.json");
const clipper::MAtomNonBond &manb = clipper::MAtomNonBond(mol, 1.0); // was 1.0

clipper::MGlycology mgl = clipper::MGlycology(mol, manb, torsions_zscore_database, false);
// std::cout << mgl.get_list_of_glycans().size() << std::endl;

std::vector<clipper::MGlycan> list_of_glycans = mgl.get_list_of_glycans();

std::vector<std::string> svg_list;

if (list_of_glycans.size() > 0)
{
int glycansPermutated = 0;
clipper::String current_chain = "";
float z_score_total_for_protein = 0;
int number_of_indiviual_glycans = 0;

for (int i = 0; i < list_of_glycans.size(); i++)
{
clipper::String wurcs_string;
if (current_chain != list_of_glycans[i].get_chain())
{
current_chain = list_of_glycans[i].get_chain();
// std::cout << std::endl
// << std::endl
// << "Chain " << current_chain[0] << std::endl
// << "-------" << std::endl;
}
// std::cout << std::endl
// << list_of_glycans[i].print_linear(true, false, true) << std::endl;

wurcs_string = list_of_glycans[i].generate_wurcs();
// std::cout << wurcs_string << std::endl;

privateer::glycanbuilderplot::Plot plot(true, true, list_of_glycans[i].get_root_by_name());
// std::vector<int> viewbox = {0,0,300,300};
// plot.set_viewbox(viewbox);
plot.plot_glycan(list_of_glycans[i]);

// plot.get_viewbox();

std::ostringstream os;
os << list_of_glycans[i].get_root_for_filename() << ".svg";
svg_list.emplace_back(plot.write_to_string());
}

return svg_list;
}
}

struct TorsionEntry {
std::string sugar_1;
std::string sugar_2;
Expand Down Expand Up @@ -106,7 +41,7 @@ struct TableEntry
};


extern "C" std::vector<TableEntry> read_file_to_table(const std::string &file, const std::string &name)
extern "C" std::vector<TableEntry> validate(const std::string &file, const std::string &name)
{

char *c_data = (char *)file.c_str();
Expand All @@ -117,10 +52,10 @@ extern "C" std::vector<TableEntry> read_file_to_table(const std::string &file, c
}

::gemmi::Structure structure = ::gemmi::read_structure_from_char_array(c_data, size, name);
std::cout << "structure read" << std::endl;
clipper::GEMMIFile gemmi_file;
clipper::GemmiStructure *gemmi_structure = &gemmi_file;
gemmi_structure->structure_ = structure;
std::cout << "[Privateer] Structure successfully imported" << std::endl;

// CHECK FOR AN PROVIDED MTZ
std::string filename = "/input.mtz";
Expand All @@ -134,14 +69,14 @@ extern "C" std::vector<TableEntry> read_file_to_table(const std::string &file, c
// mtzin.import_hkl_data( fphidata, "/*/*/[FWT,PHWT]" );
std::cout << "Found the input mtz, ready to use..." << std::endl;
} else {
std::cout << "MTZ not found" << std::endl;
std::cout << "[Privateer] No MTZ supplied, continuing..." << std::endl;
}


clipper::MiniMol mol;
gemmi_file.import_minimol(mol);

std::cout << "Mol imported" << std::endl;
std::cout << "[Privateer] Molecule generated" << std::endl;

privateer::json::GlobalTorsionZScore torsions_zscore_database = privateer::json::read_json_file_for_torsions_zscore_database("privateer_torsions_z_score_database.json");

Expand Down Expand Up @@ -218,7 +153,7 @@ extern "C" std::vector<TableEntry> read_file_to_table(const std::string &file, c

return table_list;
}
std::cout << "Table list is empty" << std::endl;
std::cout << "[Privateer] No Glycans Found" << std::endl;
return {};
}

Expand All @@ -235,7 +170,6 @@ extern "C" std::vector<TableEntry> read_file_to_table(const std::string &file, c
EMSCRIPTEN_BINDINGS(privateer_module)
{

function("read_structure", &read_file);
register_vector<std::string>("vector<string>");

value_object<TorsionEntry>("TorsionEntry")
Expand Down Expand Up @@ -266,7 +200,7 @@ EMSCRIPTEN_BINDINGS(privateer_module)

// .field("description", &TableEntry::description);

function("read_structure_to_table", &read_file_to_table);
function("validate", &validate);
register_vector<TableEntry>("Table");

}
140 changes: 70 additions & 70 deletions src/privateer/cpp/privateer-interactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,76 +16,76 @@ namespace privateer

void hydrogenate_input_model(std::string input_model, std::string output_path)
{
std::cout << "Hydrogenating '" << input_model << "' using project-gemmi/gemmi third party library." << std::endl;
try
{
std::string output;
if (output == "undefined")
output = "hydrogenated_input_model.pdb";
else
output = output_path;
gemmi::HydrogenChange h_change = gemmi::HydrogenChange::ReAdd;
std::string monomer_dir = privateer::restraints::check_monlib_access();
if (monomer_dir.empty())
throw std::runtime_error("Failed to locate $CLIBD_MON. Have ccp4 env variables been sourced?");

gemmi::Structure st = gemmi::read_structure_file(input_model);

if (st.models.empty() || st.models[0].chains.empty())
throw std::runtime_error("No atoms in the input file.");

gemmi::setup_entities(st);
size_t initial_h = 0;
initial_h = gemmi::count_hydrogen_sites(st);

std::vector<std::string> res_names = st.models[0].get_all_residue_names();

std::printf("Reading %zu monomers and all links from %s\n",
res_names.size(), input_model.c_str());

gemmi::MonLib monlib = gemmi::read_monomer_lib(monomer_dir, res_names,
gemmi::cif::read_file);

for (size_t i = 0; i != st.models.size(); ++i)
gemmi::prepare_topology(st, monlib, i, h_change, false);

std::printf("Hydrogen site count: %zu in input, %zu in output.\n",
initial_h, gemmi::count_hydrogen_sites(st));

// Clean up the H atoms that were placed at (0.00, 0.00, 0.00)
for (gemmi::Model &model : st.models)
for (gemmi::Chain &chain : model.chains)
for (gemmi::Residue &res : chain.residues)
{
std::vector<gemmi::Atom> modified_atoms;
for (gemmi::Atom &atom : res.atoms)
{
if (atom.is_hydrogen())
{
if (atom.pos.x == 0 && atom.pos.y == 0 && atom.pos.z == 0 && atom.occ == 0)
continue;
else
modified_atoms.push_back(atom);
}
else
{
modified_atoms.push_back(atom);
}
}
res.atoms = modified_atoms;
}

std::printf("Writing coordinates to %s\n", output.c_str());
gemmi::Ofstream os(output, &std::cout);
gemmi::write_pdb(st, os.ref());

std::cout << input_model << " was successfully hydrogenated!" << std::endl;
}
catch (std::exception &e)
{
std::fprintf(stderr, "ERROR: %s\n", e.what());
// throw stderr;
}
// std::cout << "Hydrogenating '" << input_model << "' using project-gemmi/gemmi third party library." << std::endl;
// try
// {
// std::string output;
// if (output == "undefined")
// output = "hydrogenated_input_model.pdb";
// else
// output = output_path;
// gemmi::HydrogenChange h_change = gemmi::HydrogenChange::ReAdd;
// std::string monomer_dir = privateer::restraints::check_monlib_access();
// if (monomer_dir.empty())
// throw std::runtime_error("Failed to locate $CLIBD_MON. Have ccp4 env variables been sourced?");

// gemmi::Structure st = gemmi::read_structure_file(input_model);

// if (st.models.empty() || st.models[0].chains.empty())
// throw std::runtime_error("No atoms in the input file.");

// gemmi::setup_entities(st);
// size_t initial_h = 0;
// initial_h = gemmi::count_hydrogen_sites(st);

// std::vector<std::string> res_names = st.models[0].get_all_residue_names();

// std::printf("Reading %zu monomers and all links from %s\n",
// res_names.size(), input_model.c_str());

// gemmi::MonLib monlib = gemmi::read_monomer_lib(monomer_dir, res_names,
// gemmi::cif::read_file);

// for (size_t i = 0; i != st.models.size(); ++i)
// gemmi::prepare_topology(st, monlib, i, h_change, false);

// std::printf("Hydrogen site count: %zu in input, %zu in output.\n",
// initial_h, gemmi::count_hydrogen_sites(st));

// // Clean up the H atoms that were placed at (0.00, 0.00, 0.00)
// for (gemmi::Model &model : st.models)
// for (gemmi::Chain &chain : model.chains)
// for (gemmi::Residue &res : chain.residues)
// {
// std::vector<gemmi::Atom> modified_atoms;
// for (gemmi::Atom &atom : res.atoms)
// {
// if (atom.is_hydrogen())
// {
// if (atom.pos.x == 0 && atom.pos.y == 0 && atom.pos.z == 0 && atom.occ == 0)
// continue;
// else
// modified_atoms.push_back(atom);
// }
// else
// {
// modified_atoms.push_back(atom);
// }
// }
// res.atoms = modified_atoms;
// }

// std::printf("Writing coordinates to %s\n", output.c_str());
// gemmi::Ofstream os(output, &std::cout);
// gemmi::write_pdb(st, os.ref());

// std::cout << input_model << " was successfully hydrogenated!" << std::endl;
// }
// catch (std::exception &e)
// {
// std::fprintf(stderr, "ERROR: %s\n", e.what());
// // throw stderr;
// }
}

privateer::interactions::CHPiBondsParser::CHPiBondsParser(std::string &input_model, std::string output_path, std::string algorithm)
Expand Down
2 changes: 1 addition & 1 deletion src/privateer/cpp/privateer-interactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "gemmi/mmread.hpp"
#include "gemmi/monlib.hpp"
#include "gemmi/placeh.hpp"
// #include "gemmi/placeh.hpp"
#include "gemmi/fstream.hpp"
#include "gemmi/cif.hpp"
#include "gemmi/to_pdb.hpp"
Expand Down
Loading