diff --git a/modules/mol/base/doc/editors.rst b/modules/mol/base/doc/editors.rst index 73d45b8adb81a4d786b981bf9c0e8ab2b230e3cb..4d272dd561c285de3e69f1ff296da8660d2bd7af 100644 --- a/modules/mol/base/doc/editors.rst +++ b/modules/mol/base/doc/editors.rst @@ -235,13 +235,13 @@ The basic functionality of editors is implemented in the EditorBase class. :type atom: :class:`EntityHandle` - .. method:: DeleteAtoms(residue) + .. method:: DeleteAtoms(atoms) Deletes a set specified atoms. All associated torsions and bonds will be removed as well - :type residue: :class:`AtomHandleList` - :param residue: A valid set of atoms + :type atoms: :class:`AtomHandleList` + :param atoms: A valid set of atoms .. method:: DeleteResidue(residue) diff --git a/modules/mol/mm/pymod/export_block_modifiers.cc b/modules/mol/mm/pymod/export_block_modifiers.cc index a6570e3aa5e342ae3724c54f827ec6b822e0d0c6..08287f08f7b7ae33080e6e9d9948ec4b060b90e3 100644 --- a/modules/mol/mm/pymod/export_block_modifiers.cc +++ b/modules/mol/mm/pymod/export_block_modifiers.cc @@ -26,6 +26,18 @@ using namespace boost::python; namespace{ +template <typename Iterator> +void AppendToList(Iterator first, Iterator last, boost::python::list& l) { + for (Iterator i = first; i != last; ++i) { + l.append(*i); + } +} + +template <typename Vec> +void AppendVectorToList(const Vec& v, boost::python::list& l) { + AppendToList(v.begin(), v.end(), l); +} + template<typename T> std::vector<T> ListToVec(const boost::python::list& l){ std::vector<T> vec; @@ -47,7 +59,8 @@ void WrapAddAddRule(ost::mol::mm::GromacsBlockModifierPtr p, } -void WrapAddHydrogenRule(ost::mol::mm::GromacsHydrogenConstructorPtr p, int number, int method, +void WrapAddHydrogenRule(ost::mol::mm::GromacsHydrogenConstructorPtr p, + int number, int method, const boost::python::list& hydrogen_names, const boost::python::list& anchors){ std::vector<String> v_hydrogen_names = ListToVec<String>(hydrogen_names); @@ -55,6 +68,91 @@ void WrapAddHydrogenRule(ost::mol::mm::GromacsHydrogenConstructorPtr p, int numb p->AddHydrogenRule(number,method,v_hydrogen_names,v_anchors); } +boost::python::list +WrapGetHydrogenRules(ost::mol::mm::GromacsHydrogenConstructorPtr p) { + // for data extraction: get all rules as list of tuples + // -> data: (number, method, names, anchors) + boost::python::list result; + for (uint i = 0; i < p->GetNumHydrogenRules(); ++i) { + int number = p->GetHydrogenRuleNumber(i); + int method = p->GetHydrogenRuleMethod(i); + boost::python::list names; + AppendVectorToList(p->GetHydrogenRuleNames(i), names); + boost::python::list anchors; + AppendVectorToList(p->GetHydrogenRuleAnchors(i), anchors); + result.append(boost::python::make_tuple(number, method, names, anchors)); + } + return result; +} + +boost::python::list WrapGetBonds(ost::mol::mm::GromacsBlockModifierPtr p) { + boost::python::list result; + AppendVectorToList(p->GetBonds(), result); + return result; +} + +boost::python::list WrapGetAngles(ost::mol::mm::GromacsBlockModifierPtr p) { + boost::python::list result; + AppendVectorToList(p->GetAngles(), result); + return result; +} + +boost::python::list WrapGetDihedrals(ost::mol::mm::GromacsBlockModifierPtr p) { + boost::python::list result; + AppendVectorToList(p->GetDihedrals(), result); + return result; +} + +boost::python::list WrapGetImpropers(ost::mol::mm::GromacsBlockModifierPtr p) { + boost::python::list result; + AppendVectorToList(p->GetImpropers(), result); + return result; +} + +boost::python::list WrapGetCmaps(ost::mol::mm::GromacsBlockModifierPtr p) { + boost::python::list result; + AppendVectorToList(p->GetCmaps(), result); + return result; +} + +boost::python::list WrapGetDeleteAtoms(ost::mol::mm::GromacsBlockModifierPtr p) { + boost::python::list result; + AppendVectorToList(p->GetDeleteAtoms(), result); + return result; +} + +boost::python::list +WrapGetReplaceRules(ost::mol::mm::GromacsBlockModifierPtr p) { + // for data extraction: get all rules as list of tuples + // -> data: (name, new_name, new_type, new_charge) + boost::python::list result; + for (uint i = 0; i < p->GetNumReplaceRules(); ++i) { + result.append(boost::python::make_tuple(p->GetReplaceRuleName(i), + p->GetReplaceRuleNewName(i), + p->GetReplaceRuleNewType(i), + p->GetReplaceRuleNewCharge(i))); + } + return result; +} + +boost::python::list +WrapGetAddRules(ost::mol::mm::GromacsBlockModifierPtr p) { + // for data extraction: get all rules as list of tuples + // -> data: (number, method, names, anchors, type, charge) + boost::python::list result; + for (uint i = 0; i < p->GetNumAddRules(); ++i) { + boost::python::list names; + AppendVectorToList(p->GetAddRuleNames(i), names); + boost::python::list anchors; + AppendVectorToList(p->GetAddRuleAnchors(i), anchors); + result.append(boost::python::make_tuple(p->GetAddRuleNumber(i), + p->GetAddRuleMethod(i), + names, anchors, + p->GetAddRuleType(i), + p->GetAddRuleCharge(i))); + } + return result; +} } @@ -72,6 +170,7 @@ void export_BlockModifiers() .def("ApplyOnBuildingBlock",&ost::mol::mm::GromacsHydrogenConstructor::ApplyOnBuildingBlock,(arg("block"))) .def("ApplyOnResidue",&ost::mol::mm::GromacsHydrogenConstructor::ApplyOnResidue,(arg("residue"),arg("editor"))) .def("AddHydrogenRule",&WrapAddHydrogenRule,(arg("number"),arg("method"),arg("hydrogen_names"),arg("anchors"))) + .def("GetHydrogenRules",&WrapGetHydrogenRules) ; class_<ost::mol::mm::GromacsBlockModifier, bases<ost::mol::mm::BlockModifier> >("GromacsBlockModifier", init<>()) @@ -85,6 +184,14 @@ void export_BlockModifiers() .def("AddImproper",&ost::mol::mm::GromacsBlockModifier::AddImproper,(arg("improper"))) .def("AddCMap",&ost::mol::mm::GromacsBlockModifier::AddCMap,(arg("cmap"))) .def("AddDeleteAtom",&ost::mol::mm::GromacsBlockModifier::AddDeleteAtom,(arg("name"))) + .def("GetBonds", &WrapGetBonds) + .def("GetAngles", &WrapGetAngles) + .def("GetDihedrals", &WrapGetDihedrals) + .def("GetImpropers", &WrapGetImpropers) + .def("GetCmaps", &WrapGetCmaps) + .def("GetDeleteAtoms", &WrapGetDeleteAtoms) + .def("GetReplaceRules", &WrapGetReplaceRules) + .def("GetAddRules", &WrapGetAddRules) ; class_<ost::mol::mm::HeuristicHydrogenConstructor, bases<ost::mol::mm::HydrogenConstructor> >("HeuristicHydrogenConstructor", init<ost::mol::mm::BuildingBlockPtr>()) diff --git a/modules/mol/mm/pymod/export_forcefield.cc b/modules/mol/mm/pymod/export_forcefield.cc index 096b6eef433b075dd3e47ab0d08791103f44a879..4a36a728e1e0f2dcf567f69953b82f2574443e70 100644 --- a/modules/mol/mm/pymod/export_forcefield.cc +++ b/modules/mol/mm/pymod/export_forcefield.cc @@ -23,16 +23,29 @@ using namespace boost::python; -namespace{ +namespace { +ost::mol::mm::InteractionPtr GetLJOneType(ost::mol::mm::ForcefieldPtr p, + String type) { + return p->GetLJ(type); +} - ost::mol::mm::InteractionPtr GetLJOneType(ost::mol::mm::ForcefieldPtr p, String type){ - return p->GetLJ(type); - } +ost::mol::mm::InteractionPtr GetLJTwoTypes(ost::mol::mm::ForcefieldPtr p, + String type1, String type2, + bool pair) { + return p->GetLJ(type1, type2, pair); +} - ost::mol::mm::InteractionPtr GetLJTwoTypes(ost::mol::mm::ForcefieldPtr p, String type1, String type2, bool pair){ - return p->GetLJ(type1,type2,pair); +boost::python::list WrapGetAtomRenamingRules(ost::mol::mm::ForcefieldPtr p, + const String& res_name) { + boost::python::list result; + typedef ost::mol::mm::Forcefield::AtomRenamingType AtomRenamingType; + const AtomRenamingType& rules = p->GetAtomRenamingRules(res_name); + for (uint i = 0; i < rules.size(); ++i) { + result.append(boost::python::make_tuple(rules[i].first, rules[i].second)); } + return result; +} } @@ -86,6 +99,9 @@ void export_Forcefield() .def("GetResidueRenamingTwoTer",&ost::mol::mm::Forcefield::GetResidueRenamingTwoTer,(arg("res_name"))) .def("GetAtomRenaming",&ost::mol::mm::Forcefield::GetAtomRenaming,(arg("res_name"),arg("atom_name"))) .def("AssignFFSpecificNames",&ost::mol::mm::Forcefield::AssignFFSpecificNames,(arg("ent"),arg("reverse")=false)) + .def("HasAtomRenamingRules", &ost::mol::mm::Forcefield::HasAtomRenamingRules, + (arg("res_name"))) + .def("GetAtomRenamingRules", &WrapGetAtomRenamingRules, (arg("res_name"))) ; boost::python::register_ptr_to_python<ost::mol::mm::ForcefieldPtr>(); diff --git a/modules/mol/mm/src/forcefield.cc b/modules/mol/mm/src/forcefield.cc index 5e1b1ac7102f9fbb32841016a6a4d179078a146a..af349dbbb5df877657d7c1c72214cc460748fe6c 100644 --- a/modules/mol/mm/src/forcefield.cc +++ b/modules/mol/mm/src/forcefield.cc @@ -836,8 +836,10 @@ String Forcefield::GetResidueRenamingTwoTer(const String& name) const{ return i->second->twoter; } -String Forcefield::GetAtomRenaming(const String& res_name, const String& atom_name) const{ - boost::unordered_map<String,std::vector<std::pair<String,String> > >::const_iterator i = atom_renaming_ff_specific_.find(res_name); +String Forcefield::GetAtomRenaming(const String& res_name, + const String& atom_name) const { + boost::unordered_map<String,AtomRenamingType>::const_iterator i; + i = atom_renaming_ff_specific_.find(res_name); if(i == atom_renaming_ff_specific_.end()) return atom_name; for(std::vector<std::pair<String,String> >::const_iterator j = i->second.begin(), e = i->second.end(); j != e; ++j){ @@ -846,6 +848,16 @@ String Forcefield::GetAtomRenaming(const String& res_name, const String& atom_na return atom_name; } +const Forcefield::AtomRenamingType& +Forcefield::GetAtomRenamingRules(const String& res_name) const { + boost::unordered_map<String,AtomRenamingType>::const_iterator i; + i = atom_renaming_ff_specific_.find(res_name); + if (i == atom_renaming_ff_specific_.end()) { + throw ost::Error(String("No atom renaming rules for ") + res_name); + } + return i->second; +} + void Forcefield::AssignFFSpecificNames(ost::mol::EntityHandle& handle, bool reverse) const{ //the whole FF specific renaming procedure assumes a standard naming, diff --git a/modules/mol/mm/src/forcefield.hh b/modules/mol/mm/src/forcefield.hh index 3c65e37fea4673f5f7f4dba2dae582e3871ad269..2c19506204284d13e9d1ddca1718e1148dec02f1 100644 --- a/modules/mol/mm/src/forcefield.hh +++ b/modules/mol/mm/src/forcefield.hh @@ -195,6 +195,14 @@ public: //Renaming to the forcefield specific names (residues/atoms) void AssignFFSpecificNames(ost::mol::EntityHandle& handle, bool reverse=false) const; + // get renaming rules (for data extraction) + bool HasAtomRenamingRules(const String& res_name) const { + return (atom_renaming_ff_specific_.find(res_name) + != atom_renaming_ff_specific_.end()); + } + typedef std::vector<std::pair<String,String> > AtomRenamingType; + const AtomRenamingType& GetAtomRenamingRules(const String& res_name) const; + private: String AtomTypesToKeyword(std::vector<String>& types, bool allow_reordering = true) const; @@ -220,7 +228,7 @@ private: boost::unordered_map<String,std::vector<InteractionPtr> > dihedrals_; boost::unordered_map<String,std::vector<InteractionPtr> > improper_dihedrals_; - boost::unordered_map<String, std::vector<std::pair<String,String> > > atom_renaming_ff_specific_; + boost::unordered_map<String, AtomRenamingType> atom_renaming_ff_specific_; boost::unordered_map<String, ResidueNamesPtr> res_renaming_ff_specific_; boost::unordered_map<String, HydrogenConstructorPtr> hydrogen_constructors_; diff --git a/modules/mol/mm/src/gromacs_block_modifiers.cc b/modules/mol/mm/src/gromacs_block_modifiers.cc index b74b567ea03ff4c8f6737fb42e5ae79400927e32..b7c6d38eabe9dd41e435bbd8cfd174473da5ee91 100644 --- a/modules/mol/mm/src/gromacs_block_modifiers.cc +++ b/modules/mol/mm/src/gromacs_block_modifiers.cc @@ -21,9 +21,9 @@ namespace ost{ namespace mol{ namespace mm{ -std::vector<geom::Vec3> GromacsPositionRuleEvaluator::EvaluatePosRule(int rule, - int number, - const std::vector<geom::Vec3>& anchors){ +std::vector<geom::Vec3> GromacsPositionRuleEvaluator::EvaluatePosRule( + int rule, int number, + const std::vector<geom::Vec3>& anchors) { std::vector<geom::Vec3> positions; @@ -194,11 +194,12 @@ std::vector<geom::Vec3> GromacsPositionRuleEvaluator::EvaluatePosRule(int rule, } -void GromacsHydrogenConstructor::ApplyOnBuildingBlock(BuildingBlockPtr p){ +void GromacsHydrogenConstructor::ApplyOnBuildingBlock(BuildingBlockPtr p) { //we assume, that the hydrogens are already correct in the building block... } -void GromacsHydrogenConstructor::ApplyOnResidue(ost::mol::ResidueHandle& res, ost::mol::XCSEditor& ed){ +void GromacsHydrogenConstructor::ApplyOnResidue(ost::mol::ResidueHandle& res, + ost::mol::XCSEditor& ed) { if(!res.IsValid()) return; @@ -230,7 +231,8 @@ void GromacsHydrogenConstructor::ApplyOnResidue(ost::mol::ResidueHandle& res, os ost::mol::AtomHandle atom; bool found_anchors = true; - for(std::vector<String>::iterator it = anchor_names.begin();it!=anchor_names.end();++it){ + for (std::vector<String>::iterator it = anchor_names.begin(); + it!=anchor_names.end(); ++it) { temp_res = res; atom_name = *it; @@ -272,23 +274,28 @@ void GromacsHydrogenConstructor::ApplyOnResidue(ost::mol::ResidueHandle& res, os continue; } - hydrogen_positions = GromacsPositionRuleEvaluator::EvaluatePosRule(method, - number, - anchor_positions); + hydrogen_positions + = GromacsPositionRuleEvaluator::EvaluatePosRule(method, number, + anchor_positions); for(int b=0;b<number;++b){ //only add hydrogen if not already present! atom = res.FindAtom(hydrogen_names[b]); - if(!atom.IsValid()) atom = ed.InsertAtom(res,hydrogen_names[b],hydrogen_positions[b],"H"); - else ed.SetAtomPos(atom,hydrogen_positions[b]); + if (!atom.IsValid()) { + atom = ed.InsertAtom(res, hydrogen_names[b], hydrogen_positions[b], "H"); + } + else { + ed.SetAtomPos(atom, hydrogen_positions[b]); + } } } } -void GromacsHydrogenConstructor::AddHydrogenRule(uint number, int method, - const std::vector<String>& hydrogen_names, - const std::vector<String>& anchors){ +void GromacsHydrogenConstructor::AddHydrogenRule( + uint number, int method, + const std::vector<String>& hydrogen_names, + const std::vector<String>& anchors) { if(number != hydrogen_names.size()){ std::stringstream ss; @@ -390,7 +397,8 @@ void GromacsBlockModifier::ApplyOnBuildingBlock(BuildingBlockPtr p){ } } -void GromacsBlockModifier::ApplyOnResidue(ost::mol::ResidueHandle& res, ost::mol::XCSEditor& ed){ +void GromacsBlockModifier::ApplyOnResidue(ost::mol::ResidueHandle& res, + ost::mol::XCSEditor& ed) { //let's resolve the replace statement for(uint i = 0; i < replace_old_atom_name_.size(); ++i){ @@ -423,9 +431,9 @@ void GromacsBlockModifier::ApplyOnResidue(ost::mol::ResidueHandle& res, ost::mol anchor_positions.push_back(at.GetPos()); anchor_atoms.push_back(at); } - std::vector<geom::Vec3> positions = GromacsPositionRuleEvaluator::EvaluatePosRule(method, - number, - anchor_positions); + std::vector<geom::Vec3> positions + = GromacsPositionRuleEvaluator::EvaluatePosRule(method, number, + anchor_positions); String ele = "H"; if(method == 8 || method == 9){ diff --git a/modules/mol/mm/src/gromacs_block_modifiers.hh b/modules/mol/mm/src/gromacs_block_modifiers.hh index af8fbbdc2ade9a8d9fcaf65d286fe68e3589c068..8ee115a3bfbc929cac62fbfc7a00942efbac0ec6 100644 --- a/modules/mol/mm/src/gromacs_block_modifiers.hh +++ b/modules/mol/mm/src/gromacs_block_modifiers.hh @@ -65,6 +65,16 @@ public: const std::vector<String>& hydrogen_names, const std::vector<String>& anchors); + // GET STUFF (for data extraction) + uint GetNumHydrogenRules() const { return add_number_.size(); } + // all getters for idx < GetNumHydrogenRules() + int GetHydrogenRuleNumber(uint idx) const { return add_number_[idx]; } + int GetHydrogenRuleMethod(uint idx) const { return methods_[idx]; } + const std::vector<String>& + GetHydrogenRuleNames(uint idx) const { return hydrogen_names_[idx]; } + const std::vector<String>& + GetHydrogenRuleAnchors(uint idx) const { return anchor_atom_names_[idx]; } + virtual void OnSave(ost::io::BinaryDataSink& ds) { ds << *this; } virtual BlockModifierType GetBlockModifierType() { return GromacsBlockModifiers; } @@ -145,6 +155,38 @@ public: void AddDeleteAtom(const String& atom_name) { delete_atom_names_.push_back(atom_name); } + // GET STUFF (for data extraction) + const std::vector<InteractionPtr>& GetBonds() const { return bonds_; } + const std::vector<InteractionPtr>& GetAngles() const { return angles_; } + const std::vector<InteractionPtr>& GetDihedrals() const { return dihedrals_; } + const std::vector<InteractionPtr>& GetImpropers() const { return impropers_; } + const std::vector<InteractionPtr>& GetCmaps() const { return cmaps_; } + const std::vector<String>& GetDeleteAtoms() const { return delete_atom_names_; } + // all idx for replace rules < GetNumReplaceRules() + uint GetNumReplaceRules() const { return replace_old_atom_name_.size(); } + const String& GetReplaceRuleName(uint idx) const { + return replace_old_atom_name_[idx]; + } + const String& GetReplaceRuleNewName(uint idx) const { + return replace_new_atom_name_[idx]; + } + const String& GetReplaceRuleNewType(uint idx) const { + return replace_new_atom_type_[idx]; + } + Real GetReplaceRuleNewCharge(uint idx) const { + return replace_new_charge_[idx]; + } + // all idx for add rules < GetNumAddRules() + uint GetNumAddRules() const { return add_add_number_.size(); } + int GetAddRuleNumber(uint idx) const { return add_add_number_[idx]; } + int GetAddRuleMethod(uint idx) const { return add_methods_[idx]; } + const std::vector<String>& + GetAddRuleNames(uint idx) const { return add_atom_names_[idx]; } + const std::vector<String>& + GetAddRuleAnchors(uint idx) const { return add_anchor_atom_names_[idx]; } + const String& GetAddRuleType(uint idx) const { return add_atom_types_[idx]; } + Real GetAddRuleCharge(uint idx) const { return add_charges_[idx]; } + virtual void OnSave(ost::io::BinaryDataSink& ds) { ds << *this; } virtual BlockModifierType GetBlockModifierType() { return GromacsBlockModifiers; }