Skip to content

Commit c1376be

Browse files
committed
Add 3D Crystal widget using py3Dmol. CreateCrystalFromCIF will now by default return a single Crystal as a python object which enables using the python methods
1 parent 75fc0c0 commit c1376be

File tree

6 files changed

+1873
-123
lines changed

6 files changed

+1873
-123
lines changed

AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Authors:
33
Christopher L. Farrow
44
Pavol Juhas
55
Simon J.L. Billinge
6+
Vincent Favre-Nicolin
67

78
Contributors:
89

examples/cimetidine-structure-solution-powder.ipynb

Lines changed: 1501 additions & 108 deletions
Large diffs are not rendered by default.

src/extensions/crystal_ext.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,29 @@ std::string _CIF(const Crystal &c, double mindist)
166166
return s.str();
167167
}
168168

169+
void _ImportCrystalFromCIF(Crystal &cryst, bp::object input,
170+
const bool oneScatteringPowerPerElement=false,
171+
const bool connectAtoms=false)
172+
{
173+
// Reading a cif file creates some output via fpObjCrystInformUser.
174+
// Mute the output and restore it on return or exception.
175+
// Also mute any hardcoded output to cout.
176+
MuteObjCrystUserInfo muzzle;
177+
CaptureStdOut gag;
178+
179+
boost_adaptbx::python::streambuf sbuf(input);
180+
boost_adaptbx::python::streambuf::istream in(sbuf);
181+
ObjCryst::CIF cif(in);
182+
183+
const bool verbose = false;
184+
const bool checkSymAsXYZ = true;
185+
ObjCryst::CreateCrystalFromCIF(cif, verbose, checkSymAsXYZ, oneScatteringPowerPerElement,
186+
connectAtoms, &cryst);
187+
188+
gag.release();
189+
muzzle.release();
190+
}
191+
169192

170193
// wrap the virtual functions that need it
171194
class CrystalWrap : public Crystal, public wrapper<Crystal>
@@ -212,6 +235,16 @@ class CrystalWrap : public Crystal, public wrapper<Crystal>
212235
return default_GetScatteringComponentList();
213236
}
214237

238+
void default_UpdateDisplay() const
239+
{ this->Crystal::UpdateDisplay();}
240+
241+
virtual void UpdateDisplay() const
242+
{
243+
override f = this->get_override("UpdateDisplay");
244+
if (f) f();
245+
else default_UpdateDisplay();
246+
}
247+
215248
};
216249

217250
// Easier than exposing all the CIF classes
@@ -350,6 +383,11 @@ void wrap_crystal()
350383
(bp::arg("min_relat_dist")=0.4, bp::arg("max_relat_dist")=1.3,
351384
bp::arg("warnuser_fail")=false))
352385
.def("GetFormula", &Crystal::GetFormula)
386+
.def("ImportCrystalFromCIF", &_ImportCrystalFromCIF, (bp::arg("input"),
387+
bp::arg("oneScatteringPowerPerElement")=false,
388+
bp::arg("connectAtoms")=false))
389+
.def("UpdateDisplay", &Crystal::UpdateDisplay,
390+
&CrystalWrap::default_UpdateDisplay)
353391
;
354392

355393

src/extensions/spacegroup_ext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ void wrap_spacegroup()
122122
.def("GetTranslationVectors", &GetTranslationVectors)
123123
.def("GetSymmetryOperations", &GetSymmetryOperations)
124124
.def("GetAllSymmetrics", &SpaceGroup::GetAllSymmetrics,
125-
(bp::arg("h"),
126-
bp::arg("k"),
127-
bp::arg("l"),
125+
(bp::arg("x"),
126+
bp::arg("y"),
127+
bp::arg("z"),
128128
bp::arg("noCenter")=false,
129129
bp::arg("noTransl")=false,
130130
bp::arg("noIdentical")=false))

0 commit comments

Comments
 (0)