Skip to content
Snippets Groups Projects
Commit 497c629b authored by Ansgar Philippsen's avatar Ansgar Philippsen
Browse files

added chain property to atom handle and view py export; fixed...

added chain property to atom handle and view py export; fixed CreateViewFromAtomList python export to accept actual python lists
parent d0ae487e
Branches
Tags
No related merge requests found
......@@ -28,6 +28,14 @@ using namespace ost::mol;
#include <ost/export_helper/generic_property_def.hh>
#include <ost/export_helper/vector.hh>
namespace {
ChainHandle get_chain(AtomHandle& a)
{
return a.GetResidue().GetChain();
}
}
void export_Atom()
{
class_<AtomBase> atom_base("AtomBase", no_init);
......@@ -81,6 +89,8 @@ void export_Atom()
class_<AtomHandle, bases<AtomBase> >("AtomHandle", init<>())
.def("GetResidue",&AtomHandle::GetResidue)
.add_property("residue",&AtomHandle::GetResidue)
.def("GetChain",get_chain)
.add_property("chain",get_chain)
.def("GetBondList", &AtomHandle::GetBondList)
.def("GetBondCount", &AtomHandle::GetBondCount)
.def("GetEntity", &AtomHandle::GetEntity)
......
......@@ -26,12 +26,21 @@ using namespace boost::python;
using namespace ost;
using namespace ost::mol;
namespace {
ChainView get_chain(AtomView& a)
{
return a.GetResidue().GetChain();
}
}
void export_AtomView()
{
class_<AtomView, bases<AtomBase> >("AtomView", init<>())
.def("GetResidue",&AtomView::GetResidue)
.add_property("residue",&AtomView::GetResidue)
.def("GetChain",get_chain)
.add_property("chain",get_chain)
.def(self==self)
.def(self!=self)
.add_property("handle", &AtomView::GetHandle)
......
......@@ -30,6 +30,17 @@ using namespace ost::mol;
namespace {
template<class T>
std::vector<T> from_list(const list& seq)
{
std::vector<T> nrvo;
for (int i = 0; i < len(seq); ++i) {
nrvo.push_back(extract<T>(seq[i]));
}
return nrvo;
}
typedef ChainView (EntityView::*StringMethod)(const String&) const;
typedef ChainView (EntityView::*StringMethod)(const String&) const;
typedef EntityView (EntityView::*QueryMethod)(const Query&, uint) const;
......@@ -45,8 +56,21 @@ StringMethod find_chain_str=&EntityView::FindChain;
QSMethod select_string=&EntityView::Select;
QueryMethod select_query=&EntityView::Select;
EntityView (*create_view_1)(const AtomHandleList&)=&CreateViewFromAtomList;
EntityView (*create_view_2)(const AtomViewList&)=&CreateViewFromAtomList;
EntityView create_view(const list& seq)
{
if(len(seq)==0) return EntityView();
extract<AtomHandle> get_handle(seq[0]);
if(get_handle.check()) {
return CreateViewFromAtomList(from_list<AtomHandle>(seq));
}
extract<AtomView> get_view(seq[0]);
if(get_view.check()) {
return CreateViewFromAtomList(from_list<AtomView>(seq));
}
throw Error("expected sequence of atom handles or atom views");
return EntityView();
}
ResidueView (EntityView::*add_res_a)(const ResidueHandle&,
ViewAddFlags)=&EntityView::AddResidue;
ResidueView (EntityView::*add_res_b)(const ResidueView&,
......@@ -164,8 +188,7 @@ void export_EntityView()
def("Difference", &Difference);
def("Intersection", &Intersection);
def("CreateViewFromAtoms", create_view_1);
def("CreateViewFromAtoms", create_view_2);
def("CreateViewFromAtoms", create_view);
def("CreateEntityFromView", &CreateEntityFromView,
arg("handle")=EntityHandle());
......
......@@ -250,6 +250,7 @@ mol::EntityView assemble_view(const std::vector<T>& l, mol::EntityView v)
{
typedef typename std::vector<T>::const_iterator Iter;
for (Iter i=l.begin(), e=l.end(); i!=e; ++i) {
if(!i->IsValid()) continue;
if (!belongs_to_same_ent(*i, v))
throw IntegrityError(combining_not_allowed);
v.AddAtom(to_handle(*i), mol::ViewAddFlag::CHECK_DUPLICATES);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment