Skip to content

Commit

Permalink
make gemmi work with pybind11 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wojdyr committed Jun 14, 2019
1 parent 16f0f8a commit 0c4e1dc
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -41,7 +41,7 @@ matrix:
install:
- |
$PYTHON -m pip --version || $PYTHON -m ensurepip --user
$PYTHON -m pip install --user pybind11==2.2.4
$PYTHON -m pip install --user pybind11
$PYTHON -c "import pybind11; print('headers: ' + pybind11.get_include(True))"
script:
- $COMPILER --version
Expand Down
3 changes: 2 additions & 1 deletion examples/matthews.py
Expand Up @@ -27,7 +27,8 @@ def gather_data():
for path in util.get_file_paths_from_args():
block = cif.read(path).sole_block()
code = cif.as_string(block.find_value('_entry.id'))
na = sum('nucleotide' in t[0] for t in block.find('_entity_poly.type'))
na = sum('nucleotide' in t[0]
for t in block.find_values('_entity_poly.type'))
vs = block.find_value('_exptl_crystal.density_percent_sol')
vm = block.find_value('_exptl_crystal.density_Matthews')
d_min = block.find_value('_refine.ls_d_res_high')
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_search.py
Expand Up @@ -7,6 +7,6 @@

for path in get_file_paths_from_args():
block = cif.read(path).sole_block()
anis = block.find("_atom_site_anisotrop.id")
anis = block.find_values("_atom_site_anisotrop.id")
if len(anis) > 50000:
print(block.name, len(anis))
10 changes: 6 additions & 4 deletions python/unitcell.cpp
Expand Up @@ -73,15 +73,15 @@ void add_unitcell(py::module& m) {
.def("apply", &FTransform::apply);


py::class_<SymImage> symimage(m, "SymImage");
symimage
py::class_<SymImage>(m, "SymImage")
.def("dist", &SymImage::dist)
.def("__repr__", [](const SymImage& self) {
return "<gemmi.SymImage cell:[" +
triple(self.box[0], self.box[1], self.box[2]) +
"] sym:" + std::to_string(self.sym_id) + ">";
});
py::enum_<SameAsu>(symimage, "Asu")

py::enum_<SameAsu>(m, "Asu")
.value("Same", SameAsu::Yes)
.value("Different", SameAsu::No)
.value("Any", SameAsu::Any);
Expand All @@ -108,8 +108,10 @@ void add_unitcell(py::module& m) {
.def("fractionalize", &UnitCell::fractionalize)
.def("orthogonalize", &UnitCell::orthogonalize)
.def("volume_per_image", &UnitCell::volume_per_image)
// since pybind11 2.3.0 having =SameAsu::Any causes "import gemmi" to fail:
// ImportError: TypeError: __int__ returned non-int (type str)
.def("find_nearest_image", &UnitCell::find_nearest_image,
py::arg("ref"), py::arg("pos"), py::arg("asu")=SameAsu::Any)
py::arg("ref"), py::arg("pos"), py::arg("asu")/*=SameAsu::Any*/)
.def("is_special_position", &UnitCell::is_special_position,
py::arg("pos"), py::arg("max_dist")=0.8)
.def("calculate_1_d2", &UnitCell::calculate_1_d2,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -155,7 +155,7 @@ def build_extensions(self):
ext_modules=ext_modules,
packages=['gemmi-examples'],
package_dir={'gemmi-examples': 'examples'},
install_requires=['pybind11==2.2.4'],
install_requires=['pybind11>=2.3.0'],
cmdclass={'build_ext': BuildExt},
zip_safe=False,
license='MPL-2.0',
Expand Down
3 changes: 2 additions & 1 deletion tests/test_mol.py
Expand Up @@ -372,7 +372,8 @@ def test_ncs(self):
ne2 = st[0].sole_residue('A', gemmi.SeqId('63'))['NE2']
direct_dist = first_atom.pos.dist(ne2.pos)
self.assertAlmostEqual(direct_dist, 34.89, delta=1e-2)
nearest_image = st.cell.find_nearest_image(first_atom.pos, ne2.pos)
nearest_image = st.cell.find_nearest_image(first_atom.pos, ne2.pos,
gemmi.Asu.Any)
nearest_dist = nearest_image.dist()
self.assertAlmostEqual(nearest_dist, 8.02, delta=1e-2)

Expand Down
2 changes: 1 addition & 1 deletion tools/upstream-check.py
Expand Up @@ -8,7 +8,7 @@
import urllib

TAGGED_REPOS = {
'pybind/pybind11': 'v2.2.4',
'pybind/pybind11': 'v2.3.0',
'taocpp/PEGTL': '2.4.0',
'cxong/tinydir': '1.2.4',
'madler/zlib': 'v1.2.11',
Expand Down

0 comments on commit 0c4e1dc

Please sign in to comment.