def write_script(self): print 'Writing the lammps script' _mainpage_ = get_entriesvalue(self.s_entry_c) _flag_ = True # data ok flag _entries_ = [ 'float', 'int', 'int', 'float:', 'float', 'int', 'float:', 'float', 'float:', 'float' ] _flag_ *= self.check_datafile(bool) _flag_ *= min(check_vars(_mainpage_[1:], _entries_)) if _flag_: self._container_['mainpage'] = _mainpage_ _script_setup_ = [ _mainpage_, self._container_['advanced'][0], self._container_['restrain'] ] self.master._script_ = self._container_ _flag_ = write_lammps_input(_script_setup_, self._convertdata_) if _flag_: print_dec_g('Lammps script done!') self.master.swapbody(3)
def getdata_and_convert(self): _autoload_ = self.objt_c[0] if not _autoload_: pop_wrg_1('Proceeding without autoload.\nThis means that any ' + 'internal address to files that are not specified ' + 'as GUI input are going to be ignored.') if self.get_entriesvalues(): data_cont = self.master._convert_['setup'] root_folder = '/'.join(data_cont[1].split('/')[:-1] + ['']) print('Root folder: {}'.format(root_folder)) sim_data, _flags_ = extract_gromacs_data(data_cont[1:-1], _autoload_) flag_done_, _sidemol_ = _flags_ config = [data_cont[-1], _sidemol_, _autoload_, root_folder] if flag_done_: try: flag_done_, data_fnam = write_lammps_data( sim_data, 'data.gro2lam', config) except KeyError as Err: err_str = '' for er in Err.args: err_str += er + ' ' pop_err_1( 'There are missing or incomplete coefficients in' + ' your input files related to: ' + err_str) flag_done_ = False except Exception as Exc: pop_err_1( 'There are inconsistencies in your input files\n' + Exc.args[0]) flag_done_ = False if flag_done_: print_dec_g('Data file generated as "data.gro2lam"') self._convertdata_ = sim_data self._convertdata_['filename'] = data_fnam self._convertdata_['config'] = config # Returning the values self.master._convertdata_ = self._convertdata_ # to ensure freshness of our dependant values self.master._script_['advanced'] = [] self.master._script_['restrain'] = [] self.master.swapbody(2) else: pop_wrg_1('The setup needs some further improvements' + 'to be runed. Please check your inputs')
def getdata_and_convert(self): _solvatedinfo_ = self.master._convert_['solvation'] if ( self.objt_c[-1].get() and _solvatedinfo_ == []): pop_wrg_1( 'First perform the solvation configuration.' + ' You can do it pressing in solvation settings gears', _i_=0 ) self.solv_b.invoke() elif self.get_entriesvalues(): data_cont = self.master._convert_['setup'] config = data_cont[-2:]+[0] sim_data, flag_done_ = extract_gromacs_data(data_cont[:-2], _solvatedinfo_, config[1:]) if flag_done_: flag_done_ = write_lammps_data( sim_data, 'data.gro2lam', config ) if flag_done_: print_dec_g( 'Data file generated as "data.gro2lam"' ) self._convertdata_ = sim_data self._convertdata_['config'] = config # Returning the values self.master._convertdata_ = self._convertdata_ self.master.swapbody(2) else: pop_wrg_1('The setup needs some further improvements' +'to be runed. Please check your inputs')
def write_lammps_data(_topodata_, data_name, _config_): ''' Write a lammps data file''' print_dec_g('Writing Lammps data file...') ####--------------- Unpacking data ----------------#### atomstyle, _, _ = _config_ atsty = ['atomic', 'angle', 'full', 'charge', 'bond', 'molecular'] style_str = '####------- ATOM STYLE < {} > --------####' _flag_ = False if atomstyle in atsty: nam = ''.join([chr(ord(l) - 32) for l in atomstyle]) print_dec_g(style_str.format(nam)) _content_ = write_lammps_data_all(_topodata_, data_name, _config_) _flag_ = True else: #if atomstyle == 'Angle': _content_ = '' exit(('Error 037!! - Atom style {} ' + 'not implemented yet').format(atomstyle)) write_file(data_name, _content_) print_dec_g('Successful writing!!') return _flag_
def config_solvation( self): title_txt = ' '*15+'Input Water name' instructions = 'Enter the atom tag letters of:' askfor = ['O in the non bonded file', 'H in the non bonded file', 'O in the .gro file', 'H in the .gro file', 'H - O partial charge' #'Na+ in the .gro file (if are present)', #'Cl- in the .gro file (if are present)' ] _solvatedinfo_ = self.master._convert_['solvation'] if _solvatedinfo_ == []: defaultanswer = ['opls_116','opls_117','OW','HW1, HW2','0.4238' #,'Na','Cl' ] else: defaultanswer = _solvatedinfo_ self.solv_b.config(bg = 'gray40', width = 45) #cyan') self.master._aux_ = [] pop = PromptPopUp(master = self.master, title = title_txt, briefing = instructions, entries_txt = askfor, entries_val = defaultanswer ) pop.wait_window() if self.master._aux_ <> [] and self.get_entriesvalues(): _app_aux_ = self.master._aux_ #============ Check inputs ================= _flag_ = 1 nb_Ox, nbHy, gro_Oxs, gro_Hys, pch= _app_aux_ _gro_f, _, _, _nbn_f, _, _, _= self.master._convert_['setup'] _flags = check_in_file( _nbn_f, nb_Ox, nbHy) print ([nb_Ox, nbHy]) list_aux = [Ox.strip(' ') for Ox in gro_Oxs.split(',')] list_aux += [Ox.strip(' ') for Ox in gro_Hys.split(',')] _flags += check_in_file( _gro_f, *list_aux) print (list_aux) try: x = float(pch) if -10<x<10: _flags += [1] partial_charges = 'Partial charges for H: {} and for O: {}' print partial_charges.format( x, x*-2) else: _flags += [0] except: _flags += [0] list_aux = [nb_Ox, nbHy] + list_aux for v in range(len(_flags)): err_txt = '' if not _flags[v] and v <> (len(_flags)-1): filename = _nbn_f if v>1: filename = _gro_f err_txt = 'Atom tag {} not found in {}' if '/' in filename: filename = filename.split('/')[-1] err_txt = err_txt.format( list_aux[v], filename) _flag_*=0 elif not _flags[v]: err_txt = 'Non valid partial charge {}'.format( pch) _flag_*=0 if err_txt<>'': pop_err_1(err_txt+'\nSetup not saved') #============ Done! ================= if _flag_: self.master._convert_['solvation'] = _app_aux_ print_dec_g('Solvation setup saved!') #self.solv_b.focus() self.solv_b.config(bg = 'lightgrey', width = 28)
def config_restrain(self): title_txt = ' ' * 28 + '+ Restrain Goups' instructions = 'Select the group to restrain' #============ grouping ================ max_index = self.check_datafile() if max_index: _defvals_ = self._container_['restrain'] if _defvals_ == []: g_names = ['all_group'] d_ids = ['{}:{}'.format(1, max_index)] kxyz_c = ['1:xyz'] rest_ens = ['1-2'] #restrained_ensembles ck_init = [0] second_c = None if self._convertdata_ <> None: _mol_niifi_ = self._convertdata_['atomsdata'][1] for mt in range(len(_mol_niifi_)): g_names.append(_mol_niifi_[mt][0]) d_ids.append('{}:{}'.format(*_mol_niifi_[mt][1:])) kxyz_c += ['1:xyz'] rest_ens += ['1-2'] ck_init += [0] else: g_names, d_ids, kxyz_c, rest_ens, ck_init = _defvals_[0] #print g_names,'\n', d_ids,'\n', kxyz_c,'\n', ck_init if _defvals_[1] <> None: second_c = _defvals_[1] else: second_c = None self.resb.config(bg='gray70') #, width = 45) #cyan') self.master._aux_ = [] pop = PromptPopUp_wck( master=self.master, title=title_txt, briefing=instructions, entries_txt=g_names, entries_val=kxyz_c, width=530, #height = 365, range_id=d_ids, res_ens=rest_ens, chck_init=ck_init, extra_but=second_c, ) pop.wait_window() if self.master._aux_ <> []: sim_len = 0 for x in self._container_['advanced'][0][-2].split('-'): if x.strip(' ') <> 'R': sim_len += 1 _res_flag_ = [[], []] _restrain_ = self.master._aux_[:] _, _d_ids, _kxyz_c, _runs_c, _res_flag_[0] = _restrain_[0] if _restrain_[1] <> None: _, au2, au3, au4, au5 = _restrain_[1][:] _restrain_aux = _d_ids + au2 + _kxyz_c + au3 + _runs_c + au4 _res_flag_[1] = au5 else: _restrain_aux = _d_ids + _kxyz_c + _runs_c _multi_ = len(_restrain_aux) / 3 _entries_ = ([['<int:int<', 1, max_index]] * _multi_ + ['float:xyz'] * _multi_ + [['<int-x-int<:0', 1, sim_len]] * _multi_) _aux_ = check_vars(_restrain_aux, _entries_, 'Restrain groups not saved!') #print _aux_ _flag_ = min(_aux_) if _flag_: if max(max(_res_flag_)): self._container_['restrain'] = _restrain_ print_dec_g('Restrain data saved') else: print('Creating 0 groups, Restraining 0 atoms') self.resb.config(bg='gray86') #, width = 45)
def further_config_script(self): defvals = [] title_txt = ' ' * 3 + '+ Simulation Parameters' instructions = 'Input further simulation parameters' askfor = [ 'Thermo output every [#ts]', 'Atom mapping', 'Pairwise interactions', "L-J/Buck rcutoff [" + u'\u00c5' + "]", "Coulomb rcutoff [" + u'\u00c5' + "]", "Neighbor skin distance [" + u'\u00c5' + "]", 'Long-range solver', 'Long-range relative error', 'Interaction 1-2:1-3:1-4', 'Neighbor delay [#ts]', 'Neighbor update [#ts]', 'Pressure control', 'Force mixing rule', 'Simulation order', 'Velocity creation Temp [K]', ] _pair_style_ = [ 'lj/cut/coul/long', 'lj/cut/coul/cut', 'lj/cut', 'buck/coul/long', 'buck', 'buck/coul/cut', #'lj/cut/tip4p/cut', 'lj/cut/tip4p/long', #'lj/gromacs', 'lj/gromacs/coul/gromacs', 'zero', 'none' ] if self._convertdata_ <> None: buckorlj = int(self._convertdata_['defaults'][0]) if buckorlj == 1: _pair_style_ = _pair_style_[:3] + _pair_style_[-2:] else: _pair_style_ = _pair_style_[3:] self._container_['advanced'][0][2] = _pair_style_[3] _kspace_ = [ 'pppm', 'pppm/cg', 'ewald', 'pppm/disp', 'ewald/disp', #'pppm/tip4p', 'pppm/disp/tip4p' ] _comb_rule_ = ['No', 'geometric', 'arithmetic', 'sixthpower'] self._container_['advanced'][1] = [ '', ['array', 'hash'], _pair_style_, '', '', '', _kspace_, '', '', '', '', ['aniso', 'iso', 'tri'], _comb_rule_, '', '' ] _defvals_ = [] for _ad_ in range(len(self._container_['advanced'][0])): if self._container_['advanced'][1][_ad_] <> '': _def_ = self._container_['advanced'][0][_ad_] _dfli_ = self._container_['advanced'][1][_ad_] _defvals_.append([_def_, _dfli_]) else: _defvals_.append(self._container_['advanced'][0][_ad_]) self.fcb.config(bg='gray70') #, width = 155) #cyan') self.master._aux_ = [] pop = PromptPopUp(master=self.master, title=title_txt, briefing=instructions, entries_txt=askfor, entries_val=_defvals_, width=400, height=565) pop.wait_window() if self.master._aux_ <> []: _advanced_ = self.master._aux_ _entries_ = [ 'int', '', '', 'float', 'float', 'float', '', 'float', 'float::', 'int', 'int', '', '', [list, '-', 'NVE', 'NVT', 'NPT', 'R'], 'float' ] _flag_ = min( check_vars(_advanced_, _entries_, 'Advanced settings not saved!')) if _flag_: self._container_['advanced'][0] = _advanced_ print_dec_g('Advanced settings saved') self.fcb.config(bg='gray86') #, width = 145)
def further_config_script( self ): ''' Section for advaced settings ''' pop_wrg_1('Advanced settings!\nChanging these parameters could result' +' in a different simulation than the base one') defvals = [] title_txt = ' '*3+'+ Simulation Parameters' instructions = 'Input further simulation parameters' askfor = ['Thermo output every [#ts]', 'Atom mapping', 'Pairwise interactions', "L-J/Buck rcutoff ["+u'\u00c5'+"]", "Coulomb rcutoff ["+u'\u00c5'+"]", "Neighbor skin distance ["+u'\u00c5'+"]", 'Long-range solver', 'Long-range relative error', 'L-J interaction 1-2:1-3:1-4', 'Coul interaction 1-2:1-3:1-4', 'Neighbor delay [#ts]', 'Neighbor update [#ts]', 'Pressure control', 'Force mixing rule', 'Velocity creation Temp [K]', 'Energy minimization tolerance', 'Simulation order', '---', 'Shake tolerance', 'Shake bonds [b#]', 'Shake angles [a#]', ] _pair_style_ = ['lj/cut/coul/long','lj/cut/coul/cut', 'lj/cut', 'lj/charmm/coul/long', 'buck/coul/long', 'buck', 'buck/coul/cut', #'lj/cut/tip4p/cut', 'lj/cut/tip4p/long', #'lj/gromacs', 'lj/gromacs/coul/gromacs', #, 'none', 'zero'] if self._convertdata_ <> None: buckorlj = int( self._convertdata_['defaults'][0]) if buckorlj == 1: _pair_style_ = _pair_style_[ :3] + [_pair_style_[ -1]] else: _pair_style_ = _pair_style_[ 3:] _kspace_ = ['pppm', 'pppm/cg', 'ewald', 'pppm/disp', 'ewald/disp', #'pppm/tip4p', 'pppm/disp/tip4p' ] _comb_rule_ = ['No','geometric', 'arithmetic', 'sixthpower'] # ['advanced'][1] in case of drop down lists, to show the other cases self._container_['advanced'][1] = [ '', ['array', 'hash'], _pair_style_, '','','', _kspace_, '', '', '', '', '', ['aniso', 'iso', 'tri'], _comb_rule_, '','','', '', '', '' ] _defvals_ = [] for _ad_ in range(len(self._container_['advanced'][0])): if self._container_['advanced'][1][_ad_] <> '': _def_ = self._container_['advanced'][0][_ad_] _dfli_ = self._container_['advanced'][1][_ad_] _defvals_.append([ _def_, _dfli_]) else: _defvals_.append(self._container_['advanced'][0][_ad_]) self.fcb.config(bg = 'gray70')#, width = 155) #cyan') self.master._aux_ = [] pop = PromptPopUp(master = self.master, title = title_txt, briefing = instructions, entries_txt = askfor, entries_val = _defvals_ , width = 400, height = 665 ) pop.wait_window() _, bnty_len, anty_len = self.check_datafile() print bnty_len, anty_len if self.master._aux_ <> []: _advanced_ = self.master._aux_ _entries_ = [ 'int', '', '', 'float', 'float', 'float', '', 'float', ['<float::<', 0.0, 1.0],['<float::<', 0.0, 1.0], 'int', 'int', '', '', 'float', 'float',[list, '-','NVE','NVT','NPT','R','M'] ,'float', ['<int-x-int<:0', 1, bnty_len], ['<int-x-int<:0', 1, anty_len] ] _flag_ = min( check_vars( _advanced_, _entries_, 'Advanced settings not saved!')) if _flag_: self._container_['advanced'][0] = _advanced_ print_dec_g('Advanced settings saved') self.fcb.config(bg = 'gray86')#, width = 145)
def write_lammps_input(_simconfig_, _topodata_=None, in_name='in.gro2lam'): ''' _simconfig_ contains the data gathered from the gui _topodata_ comes from the converted gromacs file in_name is intended as name for the input''' #=================================================== '''==== Gathering and ordering the data =====''' #=================================================== #=================================================== ####----------- SIM RAW CONFIG --------#### _simconfig_ = _simconfig_[:] (data_file, timestep, nve_steps, nvt_steps, nvt_tss, nvt_tdamp, npt_steps, npt_pss, npt_pdamp, npt_tss, npt_tdamp) = _simconfig_[0] nvt_tstart, nvt_tend = nvt_tss.split(':') npt_pstart, npt_pend = npt_pss.split(':') npt_tstart, npt_tend = npt_tss.split(':') #print (data_file, timestep, nve_steps, nvt_steps, nvt_tstart, nvt_tend, #nvt_tdamp, npt_steps, npt_pstart, npt_pend, npt_tdamp, npt_tdamp, #npt_ystart, npt_yend) i = 5 thermo, atommap, pairwiseint, lj_rcutoff, c_rcutoff = _simconfig_[1][:i] neighbordistance, lrsolver, lrerror, in12_13_14 = _simconfig_[1][i:i + 4] neighbordelay, neighborupdate, npt_kind = _simconfig_[1][i + 4:i + 7] f_comb_rule, _order_, T_init_vel = _simconfig_[1][i + 7:] #=================================================== ####------------ RESTRAIN DATA --------#### rest_line = '' group_lines = '' torestrain = [] ens_af = [] if _simconfig_[2] <> []: g_names, g_aids, k_xyz_c, runs_c, ch_init = _simconfig_[2][0][:] if _simconfig_[2][1] <> None: ####### ------------------------------------ Super interesante!! ## este es uno de esos casos donde no es posible ## utilizar += a pesar de desligar con [:] ... aux1, aux2, aux3, aux4, aux5 = _simconfig_[2][1][:] g_names = g_names + aux1 g_aids = g_aids + aux2 k_xyz_c = k_xyz_c + aux3 runs_c = runs_c + aux4 ch_init = ch_init + aux5 print '\n' for re in range(len(g_names)): if ch_init[re] == 1: print 'Restraining group ' + g_names[re] + ' in ' + runs_c[re] groupinfo = [g_names[re], g_aids[re]] group_lines += 'group {} id {}\n'.format(*groupinfo) if runs_c[re] not in ['', 'No', 'no', '0']: ens = [int(x) - 1 for x in runs_c[re].split('-')] torestrain.append([g_names[re], k_xyz_c[re], ens]) for e in ens: if e not in ens_af: ens_af.append(e) if group_lines <> '': group_lines += '\n' mix_value = { '1': 'geometric', '2': 'arithmetic', '3': 'geometric', '4': 'sixthpower' } #for mt in range(len( _mtype_)): #group_lines += 'group {} id {}:{}\n'.format(*_mtype_[mt]) _asty_d_ = { 'atomic': 1, 'charge': 2, 'bond': 3, 'angle': 4, 'full': 5, 'molecular': 5 } #=================================================== ####------------ TOPO DATA --------#### print '\n' + data_file + '\n' if _topodata_ <> None: atomstyle, _solvated_, _parametric_ = _topodata_['config'] buckorlj, comb_rule, _, f_LJ, _ = _topodata_['defaults'] else: print 'non _topodata_' atomstyle = 'full' comb_rule = '' buckorlj = 0 if f_comb_rule in mix_value.values(): mix_value_s = ' mix ' + f_comb_rule elif f_comb_rule == 'from_gromacs' and _topodata_ <> None: mix_value_s = ' mix ' + mix_value[comb_rule] else: print 'Using default mixing rule' mix_value_s = '' #=================================================== '''======= Writing Lammps data file =======''' #=================================================== _dtxt_ = '\n' + '#INIT\n' + 'units real\n' + 'boundary p p p\n' + 'atom_style ' # as I understand lammps default is 3 #_dtxt_+= '%s %d\n'.format('dimension',dimension) _dtxt_ += atomstyle + '\n' if atomstyle not in ['full', 'charge]']: # no charges if 'coul' in pairwiseint: pairwiseint = pairwiseint.split('/coul')[0] if 'none' in pairwiseint: lj_rcutoff = '' c_rcutoff = '' elif 'coul' not in pairwiseint: c_rcutoff = '' _dtxt_ += '\natom_modify map {}\n'.format(atommap) #=================================================== ####------------ SYSTEM CONFIGURATION --------#### _dsc_txt = ['pair_style {} {}'.format(pairwiseint, lj_rcutoff)] _dsc_txt.append(' {}\n'.format(c_rcutoff)) _dsc_txt.append('bond_style harmonic\n') _dsc_txt.append('angle_style harmonic\n') _dsc_txt.append('dihedral_style charmm\n') _dtxt_ += ''.join(_dsc_txt[:_asty_d_[atomstyle]]) + '\n' if 'data' in data_file: _dtxt_ += 'read_data {}\n'.format(data_file) else: _dtxt_ += 'read_restart {}\n'.format(data_file) #=================================================== ####-------------- NEIGHBOR LIST -----------#### _dtxt_ += '\nneighbor {} bin\n'.format(neighbordistance) if lrsolver <> '' and atomstyle in ['full', 'charge']: if '/coul/long' in pairwiseint: _dtxt_ += 'kspace_style {} {}\n'.format(lrsolver, lrerror) _dtxt_ += 'pair_modify shift no tail yes' + mix_value_s + '\n' _dtxt_ += 'special_bonds lj/coul {} {} {}\n'.format(*in12_13_14.split(':')) _aux_s_ = 'neigh_modify every {} delay {} check yes\n\n' _dtxt_ += _aux_s_.format(neighborupdate, neighbordelay) #=================================================== ####--------------- TIMESTEP ----------------#### _dtxt_ += 'timestep {}\n\n\n'.format(timestep) _dtxt_ += 'thermo {}\n'.format(thermo) _dtxt_ += ('thermo_style custom step temp press vol ' + 'epair emol etotal enthalpy' + '\n\n') #=================================================== ####-------------- Init VELOCITIES ----------#### aux_vel_str = 'velocity all create {} 1234567 rot yes dist gaussian\n\n' _dtxt_ += aux_vel_str.format(T_init_vel) #=================================================== ####---------------- GROUPS ----------------#### _dtxt_ += group_lines #=================================================== ####--------------- SIMULATION ------------#### ensembles = _order_.split('-') curr_time = 0 timestep = float(timestep) tounfix = [[], []] _dtxt_ += '\n' for en in range(len(ensembles)): if ens_af <> [] and en in ens_af: # RESTRAIN for re in range(len(torestrain)): if en in torestrain[re][2]: if en - 1 not in torestrain[re][2]: spring_f = 'fix rest_{0}_{1} {0} spring/self {2} {3}\n' k, xyz = torestrain[re][1].split(':') _dtxt_ += spring_f.format(torestrain[re][0], en + 1, k, xyz) unr = 0 + en while unr + 1 in torestrain[re][2]: unr += 1 name_2uf = 'rest_{0}_{1}'.format( torestrain[re][0], en + 1) tounfix = [tounfix[0] + [unr], tounfix[1] + [name_2uf]] _dtxt_ += '\n' if ensembles[en] == 'NVE' and nve_steps <> '' and nve_steps.isdigit(): steps = int(nve_steps) nve_frm = 'fix nve_name1 all nve\nrun {}\nunfix nve_name1\n\n' _dtxt_ += nve_frm.format(steps) curr_time += steps * timestep elif ensembles[en] == 'NPT' and npt_steps <> '' and npt_steps.isdigit( ): steps = int(npt_steps) npt_frm = 'fix npt_name1 all npt temp {} {} {} {} {} {} {}\n' _dtxt_ += npt_frm.format(npt_tstart, npt_tend, npt_tdamp, npt_kind, npt_pstart, npt_pend, npt_pdamp) _dtxt_ += 'run {}\nunfix npt_name1\n\n'.format(steps) curr_time += steps * timestep elif ensembles[en] == 'NVT' and nvt_steps <> '' and nvt_steps.isdigit( ): steps = int(nvt_steps) nvt_frm = 'fix nvt_name1 all nvt temp {} {} {}\n' _dtxt_ += nvt_frm.format(nvt_tstart, nvt_tend, nvt_tdamp) _dtxt_ += 'run {}\nunfix nvt_name1\n\n'.format(steps) curr_time += steps * timestep elif ensembles[en] == 'R': restart_txt = '\nwrite_restart restart.g2l_{}fs\n' _dtxt_ += restart_txt.format(int(curr_time)) if tounfix <> [[], []] and en in tounfix[0]: # UNFIX RESTRAIN for unf in range(len(tounfix[0])): if tounfix[0][unf] == en: _dtxt_ += 'unfix ' + tounfix[1][unf] + '\n' print('Writing Lammps input script...') write_file(in_name, _dtxt_) print_dec_g('Successful writing!!') #-------------------- here would be optimum some further check return True