def write_input(datadict, filename, filetag=filetagtry, endtag='end', subdir=''): endwithspace = endtag + '\n\n' with open(subdir + filename, 'w') as f: filepref = Mio.getFilePrefix(filename) for key, val in sorted(datadict.items()): if isinstance(val, np.ndarray): f.write('{0}: \n'.format(key)) Mio.my_write_array(f, val) f.write(endwithspace) elif isinstance(val, dict): dictfilename = key + '.' + filepref f.write('{0}{1}: {2}\n\n'.format(filetag, key, dictfilename)) write_input(val, dictfilename, filetag, endtag, subdir) elif isinstance(val, list): f.write('{0}{1}: \n'.format(filetag, key)) for i, subdict in enumerate(val): dictfilename = '{0}_{1}.{2}'.format(key, i, filepref) f.write(dictfilename + '\n') write_input(subdict, dictfilename, filetag, endtag, subdir) f.write(endwithspace) else: f.write('{0}: {1}\n\n'.format(key, val))
def writeLammpsDump(datadict,filename,timestep): xyarray = datadict['deformed_positions'] typesarray = datadict['types'] natoms = xyarray.shape[0] with open(filename,'w') as f: f.write('ITEM: TIMESTEP\n') f.write('{0}\n'.format(timestep)) f.write('ITEM: NUMBER OF ATOMS\n') f.write('{0}\n'.format(natoms)) f.write('ITEM: BOX BOUNDS ss ss pp\n') # may need to change this, if PBCS are implemented boxbounds = getBoxBounds(xyarray) Mio.my_write_array(f,boxbounds) f.write('ITEM: ATOMS id type xs ys zs\n') arrayout = getArrayOut(xyarray,typesarray,boxbounds) Mio.my_write_array(f,arrayout,fmt=['{:d} ']*2+['{:f} ']*3)
def writeLammpsDump(datadict, filename, timestep): xyarray = datadict['deformed_positions'] typesarray = datadict['types'] natoms = xyarray.shape[0] with open(filename, 'w') as f: f.write('ITEM: TIMESTEP\n') f.write('{0}\n'.format(timestep)) f.write('ITEM: NUMBER OF ATOMS\n') f.write('{0}\n'.format(natoms)) f.write('ITEM: BOX BOUNDS ss ss pp\n' ) # may need to change this, if PBCS are implemented boxbounds = getBoxBounds(xyarray) Mio.my_write_array(f, boxbounds) f.write('ITEM: ATOMS id type xs ys zs\n') arrayout = getArrayOut(xyarray, typesarray, boxbounds) Mio.my_write_array(f, arrayout, fmt=['{:d} '] * 2 + ['{:f} '] * 3)
def write_input(datadict,filename,filetag=filetagtry,endtag='end',subdir=''): endwithspace = endtag + '\n\n' with open(subdir+filename,'w') as f: filepref = Mio.getFilePrefix(filename) for key, val in sorted(datadict.items()): if isinstance(val,np.ndarray): f.write('{0}: \n'.format(key)) Mio.my_write_array(f,val) f.write(endwithspace) elif isinstance(val,dict): dictfilename = key + '.' + filepref f.write('{0}{1}: {2}\n\n'.format(filetag,key,dictfilename)) write_input(val,dictfilename,filetag,endtag,subdir) elif isinstance(val,list): f.write('{0}{1}: \n'.format(filetag,key)) for i, subdict in enumerate(val): dictfilename = '{0}_{1}.{2}'.format(key,i,filepref) f.write(dictfilename + '\n') write_input(subdict,dictfilename,filetag,endtag,subdir) f.write(endwithspace) else: f.write('{0}: {1}\n\n'.format(key,val))