Skip to content

Commit

Permalink
Renamed backend call to validate
Browse files Browse the repository at this point in the history
Removed offending privateer-interactions code
Preparing Moorhen release
  • Loading branch information
Dialpuri committed Jan 11, 2024
1 parent 0d975a6 commit 71545d6
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 147 deletions.
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
7 changes: 5 additions & 2 deletions webapp/src/pages/Home/HomeSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function HomeSection(): Element {
}
setFileContent(fileContent);

const x = Module.read_structure_to_table(fileContent, name);
const x = Module.validate(fileContent, name);

const tableData: TableDataEntry[] = [];
for (let i = 0; i < x.size(); i++) {
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function HomeSection(): Element {
async function handleLoad(): Promise<void> {
if (PDBCode !== '') {
setLoadingText(
`Fetching ${PDBCode.toUpperCase()} from the PDB`
`Fetching density for ${PDBCode.toUpperCase()} from the PDB`
);

try {
Expand All @@ -91,6 +91,9 @@ export default function HomeSection(): Element {
console.log('No map found, continuing...');
}

setLoadingText(
`Fetching coordinates for ${PDBCode.toUpperCase()} from the PDB`
);
fetchPDB(PDBCode)
.then((response: ArrayBuffer) => {
setFileContent(response);
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/wasm/privateer.js

Large diffs are not rendered by default.

Binary file modified webapp/src/wasm/privateer.wasm
Binary file not shown.

0 comments on commit 71545d6

Please sign in to comment.