File: bind_vatom.cpp

package info (click to toggle)
apbs 3.4.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 199,188 kB
  • sloc: ansic: 284,988; cpp: 60,416; fortran: 44,896; xml: 13,895; sh: 13,838; python: 8,105; yacc: 2,922; makefile: 1,428; f90: 989; objc: 448; lex: 294; awk: 266; sed: 205; java: 134; csh: 79
file content (50 lines) | stat: -rw-r--r-- 1,601 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "bind_vatom.hpp"
#include <cstdio>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>

void bind_vatom(py::module& m)
{
  py::class_<sVatom>(m, "Vatom")
    .def(py::init<>())
    .def("copyTo"            , &Vatom_copyTo)
    .def("copyFrom"          , &Vatom_copyFrom)
    .def_readwrite("radius"  , &sVatom::radius)
    .def_readwrite("charge"  , &sVatom::charge)
    .def_readwrite("partID"  , &sVatom::partID)
    .def_readwrite("epsilon" , &sVatom::epsilon)
    .def_readwrite("id"      , &sVatom::id)
    .def_property("position",
        [] (sVatom& self)
        {
          return std::vector<double>(self.position, self.position+3);
        },
        [] (sVatom& self, py::array_t<double> other)
        {
          py::buffer_info buf = other.request();
          assert(buf.ndim == 1 && "Vatom::position is 1D!");
          assert(other.size() == 3 && "Vatom::position has length 3!");
          auto* ptr = static_cast<double*>(buf.ptr);
          for(int i=0;i<3;i++) self.position[i] = ptr[i];
        })
    .def_property("atomName",
        &Vatom_getAtomName,
        [] (sVatom& self, std::string other)
        {
          for(int i=0;i<VMAX_RECLEN;i++)
          {
            if(other.c_str()[i]=='\0') break;
            self.atomName[i] = other.c_str()[i];
          }
        })
    .def_property("resName",
        &Vatom_getResName,
        [] (sVatom& self, std::string other)
        {
          for(int i=0;i<VMAX_RECLEN;i++)
          {
            if(other.c_str()[i]=='\0') break;
            self.resName[i] = other.c_str()[i];
          }
        });
}