Skip to content

Commit

Permalink
Remove spacegroup requirement for input density files. Check for equa…
Browse files Browse the repository at this point in the history
…l voxel spacing for each axis.
  • Loading branch information
latrocinia committed Oct 29, 2018
1 parent f59c22e commit d7d8af7
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions powerfit/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def tofile(self, fid, fmt=None):
elif fmt in ('xplor', 'cns'):
to_xplor(fid, self)
else:
raise ValueError("Format is not supported.")
raise RuntimeError("Format is not supported.")


# builders
Expand Down Expand Up @@ -273,17 +273,36 @@ def __init__(self, fid):
# get the header
self._get_header()
# Symmetry and non-rectangular boxes are not supported.
error = (self.header['ispg'] != 1 or
self.header['alpha'] != self.header['beta'] !=
self.header['gamma'] != 90)
if error:
msg = "Only densities with P1-symmetry in rectangular boxes are supported."
raise ValueError(msg)
is_orthogonal = True
for angle_name in ['alpha', 'beta', 'gamma']:
angle = self.header[angle_name]
if abs(angle - 90) > 1e-3:
is_orthogonal = False
break
if not is_orthogonal:
msg = "Only densities in rectangular boxes are supported."
raise RuntimeError(msg)

# check the order of axis in the file
self._get_order()
# determine the voxelspacing and origin
self.voxelspacing = self.header['xlength'] / self.header['nx']
spacings = []
for axis_name in 'xyz':
length = self.header[axis_name + 'length']
nvoxels = self.header['n' + axis_name]
spacing = length / float(nvoxels)
spacings.append(spacing)

equal_spacing = True
average = sum(spacings) / float(len(spacings))
for spacing in spacings:
if abs(spacing - average) > 1e-4:
equal_spacing = False
if not equal_spacing:
msg = "Voxel spacing is not equal in all directions."
raise RuntimeError(msg)

self.voxelspacing = spacings[0]
self.origin = self._get_origin()
# generate the density
shape_fields = 'nz ny nx'.split()
Expand All @@ -298,7 +317,7 @@ def _get_endiannes(self):
elif m_stamp == '0x11':
endian = '>'
else:
raise ValueError('Endiannes is not properly set in file. Check the file format.')
raise RuntimeError('Endiannes is not properly set in file. Check the file format.')
self._endian = endian
self.fhandle.seek(0)

Expand Down

0 comments on commit d7d8af7

Please sign in to comment.