Skip to content
Snippets Groups Projects
Commit c7dfb42e authored by Studer Gabriel's avatar Studer Gabriel
Browse files

use ost logger in molck

parent d27c1eac
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,14 @@
#include <ost/conop/rule_based.hh>
#include <ost/mol/alg/molck.hh>
#include <ost/message.hh>
#include <ost/log.hh>
using namespace ost::conop;
using namespace ost::mol;
namespace ost{ namespace mol{ namespace alg{
void ost::mol::alg::MapNonStandardResidues(EntityHandle& ent, CompoundLibPtr lib) {
void MapNonStandardResidues(EntityHandle& ent, CompoundLibPtr lib, bool log_diags) {
// TODO: Maybe it is possible to make it in-place operation
if(!lib) {
......@@ -45,18 +47,17 @@ void ost::mol::alg::MapNonStandardResidues(EntityHandle& ent, CompoundLibPtr lib
continue;
}
ResidueHandle dest_res = new_edi.AppendResidue(new_chain,OneLetterCodeToResidueName(compound->GetOneLetterCode()),r->GetNumber());
ost::mol::alg::CopyResidue(*r,dest_res,new_edi,lib);
CopyResidue(*r,dest_res,new_edi,lib);
}
}
}
ent = new_ent;
// Since we didn't do it in-place: reprocess the new entity
RuleBasedProcessor pr(lib);
pr.Process(ent);
pr.Process(ent, log_diags);
}
void ost::mol::alg::RemoveAtoms(
EntityHandle& ent,
void RemoveAtoms(EntityHandle& ent,
CompoundLibPtr lib,
bool rm_unk_atoms,
bool rm_non_std,
......@@ -73,29 +74,33 @@ void ost::mol::alg::RemoveAtoms(
Diagnostics diags;
Checker checker(lib, ent, diags);
if (rm_zero_occ_atoms) {
std::cerr << "removing atoms with zero occupancy" << std::endl;
LOG_INFO("removing atoms with zero occupancy");
int zremoved=0;
AtomHandleList zero_atoms=checker.GetZeroOccupancy();
for (AtomHandleList::const_iterator i=zero_atoms.begin(), e=zero_atoms.end(); i!=e; ++i) {
edi.DeleteAtom(*i);
zremoved++;
}
std::cerr << " --> removed " << zremoved << " atoms with zero occupancy" << std::endl;
std::stringstream ss;
ss << " --> removed " << zremoved << " atoms with zero occupancy";
LOG_INFO(ss.str());
}
if (rm_hyd_atoms) {
std::cerr << "removing hydrogen atoms" << std::endl;
LOG_INFO("removing hydrogen atoms");
int hremoved=0;
AtomHandleList hyd_atoms=checker.GetHydrogens();
for (AtomHandleList::const_iterator i=hyd_atoms.begin(), e=hyd_atoms.end(); i!=e; ++i) {
edi.DeleteAtom(*i);
hremoved++;
}
std::cerr << " --> removed " << hremoved << " hydrogen atoms" << std::endl;
std::stringstream ss;
ss << " --> removed " << hremoved << " hydrogen atoms";
LOG_INFO(ss.str());
}
if (rm_oxt_atoms) {
std::cerr << "removing OXT atoms" << std::endl;
LOG_INFO("removing OXT atoms");
int oremoved=0;
AtomHandleList atoms=ent.GetAtomList();
for (AtomHandleList::const_iterator i=atoms.begin(), e=atoms.end(); i!=e; ++i) {
......@@ -104,7 +109,9 @@ void ost::mol::alg::RemoveAtoms(
oremoved++;
}
}
std::cerr << " --> removed " << oremoved << " OXT atoms" << std::endl;
std::stringstream ss;
ss << " --> removed " << oremoved << " OXT atoms";
LOG_INFO(ss.str());
}
checker.CheckForCompleteness();
......@@ -113,28 +120,29 @@ void ost::mol::alg::RemoveAtoms(
for (Diagnostics::const_diag_iterator
j = diags.diags_begin(), e = diags.diags_end(); j != e; ++j) {
const Diag* diag=*j;
std::cerr << diag->Format(colored);
std::stringstream ss;
ss << diag->Format(colored);
switch (diag->GetType()) {
case DIAG_UNK_ATOM:
if (rm_unk_atoms) {
edi.DeleteAtom(diag->GetAtom(0));
std::cerr << " --> removed ";
ss << " --> removed ";
}
break;
case DIAG_NONSTD_RESIDUE:
if (rm_non_std) {
edi.DeleteResidue(diag->GetResidue(0));
std::cerr << " --> removed ";
ss << " --> removed ";
}
break;
default:
break;
}
std::cerr << std::endl;
LOG_INFO(ss.str());
}
}
void ost::mol::alg::CleanUpElementColumn(EntityHandle& ent, CompoundLibPtr lib){
void CleanUpElementColumn(EntityHandle& ent, CompoundLibPtr lib){
if(!lib) {
throw ost::Error("Require valid compound library!");
......@@ -164,20 +172,19 @@ void ost::mol::alg::CleanUpElementColumn(EntityHandle& ent, CompoundLibPtr lib){
}
}
void ost::mol::alg::Molck(
ost::mol::EntityHandle& ent,
void Molck(ost::mol::EntityHandle& ent,
ost::conop::CompoundLibPtr lib,
const ost::mol::alg::MolckSettings& settings=ost::mol::alg::MolckSettings()){
const MolckSettings& settings = MolckSettings()){
if(!lib) {
throw ost::Error("Require valid compound library!");
}
if (settings.map_nonstd_res) {
ost::mol::alg::MapNonStandardResidues(ent, lib);
MapNonStandardResidues(ent, lib, false);
}
ost::mol::alg::RemoveAtoms(ent,
lib,
RemoveAtoms(ent, lib,
settings.rm_unk_atoms,
settings.rm_non_std,
settings.rm_hyd_atoms,
......@@ -185,7 +192,8 @@ void ost::mol::alg::Molck(
settings.rm_zero_occ_atoms,
settings.colored);
if (settings.assign_elem) {
ost::mol::alg::CleanUpElementColumn(ent, lib);
CleanUpElementColumn(ent, lib);
}
}
}}} // ns
\ No newline at end of file
......@@ -80,7 +80,8 @@ struct MolckSettings{
};
void MapNonStandardResidues(ost::mol::EntityHandle& ent,
ost::conop::CompoundLibPtr lib);
ost::conop::CompoundLibPtr lib,
bool log_diags = true);
void RemoveAtoms(ost::mol::EntityHandle& ent,
ost::conop::CompoundLibPtr lib,
......
......@@ -11,6 +11,7 @@
#include <ost/io/mol/mmcif_reader.hh>
#include <ost/io/io_exception.hh>
#include <ost/mol/alg/molck.hh>
#include <ost/log.hh>
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#endif
......@@ -47,7 +48,7 @@ const char* USAGE=
void usage()
{
std::cerr << USAGE << std::endl;
LOG_INFO(USAGE);
exit(0);
}
......@@ -69,12 +70,14 @@ EntityHandle load_x(const String& file, const IOProfile& profile)
reader.Import(ent);
return ent;
}
std::cerr << "ERROR: '" << file << "' does not contain any ATOM records. "
<< "Are you sure this is a PDB file?" << std::endl;
std::stringstream ss;
ss << "ERROR: '" << file << "' does not contain any ATOM records. "
<< "Are you sure this is a PDB file?";
LOG_INFO(ss.str());
return EntityHandle();
}
} catch (std::exception& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
LOG_ERROR("ERROR: " << e.what());
return EntityHandle();
}
}
......@@ -86,7 +89,7 @@ ost::conop::CompoundLibPtr load_compound_lib(const String& custom_path)
if (fs::exists(custom_path)) {
return ost::conop::CompoundLib::Load(custom_path);
} else {
std::cerr << "Could not find compounds.chemlib at the provided location, trying other options" << std::endl;
LOG_INFO("Could not find compounds.chemlib at the provided location, trying other options");
}
}
if (fs::exists("compounds.chemlib")) {
......@@ -105,8 +108,8 @@ ost::conop::CompoundLibPtr load_compound_lib(const String& custom_path)
exe_path = std::string( result, (count > 0) ? count : 0 );
#endif
if (exe_path.empty()) {
std::cerr << "Could not determine the path of the molck executable. Will only "
"look for compounds.chemlib in the current working directory" << std::endl;
LOG_INFO("Could not determine the path of the molck executable. Will only "
"look for compounds.chemlib in the current working directory");
} else {
fs::path path_and_exe(exe_path);
fs::path path_only=path_and_exe.branch_path();
......@@ -120,7 +123,7 @@ ost::conop::CompoundLibPtr load_compound_lib(const String& custom_path)
}
}
if (!lib) {
std::cerr << "Could not load compounds.chemlib" << std::endl;
LOG_ERROR("Could not load compounds.chemlib");
exit(-1);
}
return ost::conop::CompoundLibPtr();
......@@ -129,6 +132,9 @@ ost::conop::CompoundLibPtr load_compound_lib(const String& custom_path)
int main(int argc, char *argv[])
{
// setup logging
ost::Logger::Instance().PushVerbosityLevel(ost::Logger::INFO);
if (argc<2) {
usage();
}
......@@ -166,7 +172,7 @@ int main(int argc, char *argv[])
options(desc).positional(p).run(),
vm);
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
LOG_ERROR(e.what());
usage();
exit(-1);
}
......@@ -206,7 +212,9 @@ int main(int argc, char *argv[])
} else if (rms[i] == StringRef("zeroocc", 7)) {
settings.rm_zero_occ_atoms = true;
} else {
std::cerr << "unknown value to remove '" << rms[i] << "'" << std::endl;
std::stringstream ss;
ss << "unknown value to remove '" << rms[i] << "'";
LOG_ERROR(ss.str());
usage();
exit(-1);
}
......@@ -246,8 +254,7 @@ int main(int argc, char *argv[])
try {
fs::path out_path(output_blueprint_string_copy);
if (out_path.has_parent_path() && !exists(out_path.parent_path())) {
std::cerr << "Output path does not exist: "
<< output_blueprint_string_copy << std::endl;
LOG_ERROR("Output path does not exist: " + output_blueprint_string_copy);
exit(-1);
}
} catch (std::exception& e) {
......@@ -255,15 +262,14 @@ int main(int argc, char *argv[])
size_t perden = String(e.what()).find("Permission denied");
if (perden != String::npos) {
std::cerr << "Cannot write into output directory: "
<< output_blueprint_string_copy << std::endl;
LOG_ERROR("Cannot write into output directory: " + output_blueprint_string_copy);
exit(-1);
} else {
std::cerr << e.what() << std::endl;
LOG_ERROR(e.what());
exit(-1);
}
}
std::cerr << "Writing out file: " << output_blueprint_string_copy << std::endl;
LOG_INFO("Writing out file: " + output_blueprint_string_copy);
PDBWriter writer(output_blueprint_string_copy, prof);
writer.Write(ent);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment