Comments (6)
Hi Jack,
regarding phase_shift()
-- thanks for pointing it out, I've changed it as you proposed.
regarding vectorization in Python - I was considering vectorization of some functions, because after reading pybind11 it seems like an easy thing to do:
https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html#vectorizing-functions
But I haven't experimented with it yet.
I don't know if working with reflection data in numpy arrays will be a common use case :-)
You are probably the first person doing this, these functions are not even documented yet.
But on the other hand, these functions are good candidates for vectorization.
In your use case, are these the only functions that would benefit from vectorization?
from gemmi.
Hi Marcin,
Thanks for taking care of this so quickly.
Working with reflection data in numpy arrays may not be a common use case yet, but I hope it will be some day! In general, I think any function that maps HKL indices in a pairwise manner to something (either other HKLs or floats) ought to be a good candidate for vectorization. I've been using 3 functions that meet that criteria:
Op.apply_to_hkl()
Op.phase_shift()
UnitCell.calculate_d()
Looking at the call signature for UnitCell.calculate_d()
, it takes 3 sequential float
arguments:
calculate_d(self: gemmi.UnitCell, hk: float, k: float, l: float) -> float
Please let me know if you think it also makes sense to change the signature of this one as well:
calculate_d(self: gemmi.UnitCell, hkl: List[float[3]]) -> float
If it ends up being straightforward to vectorize these functions (the pybind11 documentation certainly makes it seem like close to a one-liner), I think these changes in call signatures will make the syntax for these functions most consistent.
from gemmi.
Hi Jack,
I changed calculate_d and calculate_1_d2, but vectorization is not that simple.
It would be simple if the arguments were single numbers (i.e. h, k and l separately, not [h,k,l]), and if the result would also be a single number. So apply_to_hkl() is particularly problematic because of the return value.
Maybe if hkl was passed around in some structured numpy datatype it would work, but I'm not sure.
from gemmi.
Got it -- thanks for the changes in call signatures.
For now, I have vectorized versions of in my code that use attributes of gemmi.Op
and numpy
functions. This is definitely an example of "passing around as structured numpy datatypes", though, as you mentioned.
for example:
def apply_to_hkl(H, op):
"""
H : np.ndarray
(n x 3) numpy array of Miller indices
op : gemmi.Op
symmetry operation
"""
return np.floor_divide(np.matmul(H, op.rot), op.DEN)
from gemmi.
Neat! That's probably the best solution.
Let me know when your package is publicly available.
from gemmi.
I'm going to close this issue -- it may be worth revisiting vectorization in the future, but I will keep it in our package for now.
I will be sure to let you know when we release our code!
from gemmi.
Related Issues (20)
- CID parser syntax error when negative sequence number is present
- auto completion for gemmi grep HOT 1
- Uses of graph isomorphism and pynauty? HOT 2
- Segfault when importing `gemmi.cif` HOT 2
- crash with very large mmCIF files (and large number of datablock) in gemmi grep HOT 11
- Missing _struct_ref_seq in cif generated from PDB without optional TER. HOT 2
- Apparent sudden extra dependency for gemmi (zlib) HOT 5
- sequence aligning with align_sequence_to_polymer HOT 10
- TER's effecting aligning HOT 4
- Adding additional properties to the Structure object present in the cif atom_site table HOT 1
- [FEATURE REQUEST] Add Python typing for `Vec3.__iter__` HOT 2
- crash with set_extent HOT 4
- Bug in `get_all_unit_cell_sites()` HOT 5
- pdb/cif entity subchain comparisons HOT 1
- Advice to deal with AF3's broken CIF files HOT 1
- Gemmi read_ccp4_map fails to correctly set the correct spacing from a .MAP file HOT 2
- [Bug Report] read_pdb mishandle the columns of extreme wild pdb files HOT 5
- [Question] bulk reading mmcif coordinates into a numpy array HOT 2
- Creating a structure from list of residues and their coordinates HOT 2
- Float comparison fails `static_assert(weights[static_cast<int>(El::D)] == 2.0141, "Hmm")` on some architectures HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gemmi.