def _incarify(value):
"""Format value of any compatible type into the string forat appropriate for INCAR files"""
result = None
if isinstance(value, (str, unicode)):
result = value
elif not np.isscalar(value):
value_array = np.array(value)
shape = value_array.shape
dim = len(shape)
if dim == 1:
result = ' '.join([_incarify(i) for i in value])
elif dim == 2:
result = '\n'.join([_incarify(i) for i in value])
elif dim > 2:
raise TypeError('you are trying to input a more ' +
'than 2-dimensional array to VASP.' +
'Not sure what to do...')
elif isinstance(value, bool):
result = '.True.' if value else '.False.'
elif np.isreal(value):
result = '{}'.format(value)
return result
评论列表
文章目录