Skip to content

Commit 2cbd25c

Browse files
authored
Merge pull request #33 from Baharis/property_at_focus
Property at focus
2 parents 97056be + 5796393 commit 2cbd25c

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = u'Daniel Tchoń'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '0.2.1'
25+
release = '0.2.2'
2626

2727

2828
# -- General configuration ---------------------------------------------------

hikari/dataframes/hkl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def fill(self, radius=2.0):
571571
def _make_hkl_ball(i=max_index):
572572
hkl_grid = np.mgrid[-i:i:2j*i+1j, -i:i:2j*i+1j, -i:i:2j*i+1j]
573573
hkls = np.stack(hkl_grid, -1).reshape(-1, 3)
574-
xyz = np.matrix((self.a_w, self.b_w, self.c_w))
574+
xyz = np.array((self.a_w, self.b_w, self.c_w))
575575
return hkls[lin.norm(hkls @ xyz, axis=1) <= radius]
576576
hkl = _make_hkl_ball()
577577

hikari/scripts/angular_explorer.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import numpy as np
99
from numpy import linalg as lin
10+
import pandas as pd
1011

1112
from hikari.dataframes import HklFrame, LstFrame
1213
from hikari.symmetry import SG, Group
@@ -184,7 +185,7 @@ def _draw_map(self, artist, extension):
184185
a.x_axis = self.hkl_frame.a_w / lin.norm(self.hkl_frame.a_w)
185186
a.y_axis = self.hkl_frame.b_w / lin.norm(self.hkl_frame.b_w)
186187
a.z_axis = self.hkl_frame.c_w / lin.norm(self.hkl_frame.c_w)
187-
a.focus = self.focus
188+
a.focus = self.focus_cartesian
188189
a.heat_limits = self.prop_limits
189190
a.heat_palette = self.axis
190191
a.histogram = self.histogram
@@ -243,7 +244,7 @@ def lg(self):
243244
return self._lg
244245

245246
@property
246-
def focus(self):
247+
def focus_cartesian(self):
247248
_focus = []
248249
if self.orientation is not None:
249250
if len(self.orientation.shape) == 1:
@@ -259,6 +260,28 @@ def focus(self):
259260
_focus.append(v / lin.norm(v))
260261
return _focus
261262

263+
@property
264+
def focus_spherical_closest(self):
265+
_focus = []
266+
if self.orientation is not None:
267+
for focus_vector in self.focus_cartesian:
268+
_, th, ph = np.rad2deg(cart2sph(*focus_vector))
269+
th_closest = min(self.th_range, key=lambda x: abs(x - th))
270+
ph_closest = min(self.ph_range, key=lambda x: abs(x - ph))
271+
_focus.append([1.0, th_closest, ph_closest])
272+
return _focus
273+
274+
@property
275+
def prop_at_focus_closest(self):
276+
df = pd.DataFrame({'ph': self.data_dict['ph'],
277+
'th': self.data_dict['th'],
278+
'p': self.data_dict[self.property_name]})
279+
properties_ = []
280+
for _, th, ph in self.focus_spherical_closest:
281+
row = df.loc[(df['th'] == th) & (df['ph'] == ph)].iloc[0]
282+
properties_.append(row['p'])
283+
return properties_
284+
262285
@property
263286
def th_range(self):
264287
return self.th_limits.arange(step=self.angle_res)
@@ -323,6 +346,15 @@ def descriptive_statistics_string(self):
323346
f'# avg ={avg_p:8.5f}\n'
324347
return s
325348

349+
@property
350+
def prop_at_focus_string(self):
351+
s = f'# value of {self.property_name} at focus points:\n'
352+
for focus_, prop_ in zip(self.focus_spherical_closest,
353+
self.prop_at_focus_closest):
354+
_, th, ph = focus_
355+
s += f'# val ={prop_:8.5f} at th ={th :6.1f} ph ={ph :6.1f}\n'
356+
return s + '\n'
357+
326358

327359
class AngularPotencyExplorer(AngularPropertyExplorer):
328360
hkl_is_read_not_generated = False
@@ -358,6 +390,8 @@ def explore(self):
358390
lst.write('\n')
359391

360392
np.savetxt(dat_path, potency_mesh)
393+
if self.orientation is not None:
394+
lst.write(self.prop_at_focus_string)
361395
lst.write(self.descriptive_statistics_string)
362396
lst.close()
363397

@@ -408,6 +442,8 @@ def explore(self):
408442
lst.write('\n')
409443

410444
np.savetxt(dat_path, r1_mesh)
445+
if self.orientation is not None:
446+
lst.write(self.prop_at_focus_string)
411447
lst.write(self.descriptive_statistics_string)
412448
lst.close()
413449

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
setup(
2727
name='hikari-toolkit',
28-
version='0.2.1',
28+
version='0.2.2',
2929
author='Daniel Tchoń',
3030
author_email='[email protected]',
3131
packages=find_packages(exclude=('legacy', )),

test/test_scripts.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import tempfile
33
import unittest
44

5-
from hikari.scripts import calculate_similarity_indices
5+
import numpy as np
6+
7+
from hikari.scripts import calculate_similarity_indices, potency_map
68

79

810
nacl_cif_path = str(pathlib.Path(__file__).parent.joinpath('NaCl.cif'))
@@ -65,5 +67,22 @@ def test_calculate_similarity_index_for_negative_adps(self):
6567
self.assertAlmostEqual(float(last_line_contents[-3]), 50.0)
6668

6769

70+
class TestHklPotencyScripts(unittest.TestCase):
71+
temp_dir = tempfile.TemporaryDirectory()
72+
hkl_path = str(pathlib.Path(temp_dir.name) / 'potency.hkl')
73+
74+
def test_potency_map_simple(self):
75+
potency_map(a=10, b=10, c=10, al=90, be=90, ga=90, space_group='P1',
76+
path=self.hkl_path, output_quality=2, wavelength='MoKa')
77+
78+
def test_potency_map_with_focus(self):
79+
ori = np.array([[-0.08263, +0.00536, -0.03667],
80+
[-0.01671, -0.03679, -0.03238],
81+
[+0.06030, +0.02438, -0.04088]])
82+
potency_map(a=10, b=10, c=10, al=90, be=90, ga=90, space_group='Pm-3m',
83+
path=self.hkl_path, output_quality=2, wavelength='MoKa',
84+
orientation=ori)
85+
86+
6887
if __name__ == '__main__':
6988
unittest.main()

0 commit comments

Comments
 (0)