better user experience

- no meaningless warnings regarding floating point precision
- meaningful error message for invalid header
This commit is contained in:
Martin Diehl 2020-08-26 23:54:56 +02:00
parent da46e5ea9a
commit 229f6139c8
1 changed files with 8 additions and 5 deletions

View File

@ -300,13 +300,16 @@ class Geom:
f = fname
f.seek(0)
header_length,keyword = f.readline().split()[:2]
header_length = int(header_length)
content = f.readlines()
try:
header_length,keyword = f.readline().split()[:2]
header_length = int(header_length)
except ValueError:
header_length,keyword = (-1, 'invalid')
if not keyword.startswith('head') or header_length < 3:
raise TypeError('Header length information missing or invalid')
content = f.readlines()
comments = []
for i,line in enumerate(content[:header_length]):
items = line.split('#')[0].lower().strip().split()
@ -584,7 +587,7 @@ class Geom:
- ((np.ones(3)-(1./self.grid if np.array(center).dtype in np.sctypes['int'] else 0))*0.5 if periodic else c) # periodic center is always at CoG
coords_rot = R.broadcast_to(tuple(self.grid))@coords
with np.errstate(over='ignore',under='ignore'):
with np.errstate(over='ignore',under='ignore',invalid='ignore'):
mask = np.where(np.sum(np.power(coords_rot/r,2.0**exponent),axis=-1) <= 1.0,False,True)
if periodic: # translate back to center