Esempio n. 1
0
    def check_datafile(self, _bflag_=None):
        ''' function to get the max atom number 
            also is used in case of no gromacs direct data conversion
            to somehow make a check if that file is ok
        '''
        max_index = 0
        _flag_ = True
        if self._convertdata_ <> None:
            max_index = len(self._convertdata_['atomsdata'][0])
        else:
            _filename_ = self.s_entry_c[0].get()
            try:
                with open(_filename_, 'r') as indata:
                    for k_line in indata:
                        if not k_line.startswith('#'):
                            line_c = k_line.split()
                            if 'atoms' in line_c:
                                max_index = line_c[0]
                                break
            except IOError:
                pop_wrg_1('Data file not found!')
                print('Try performing a conversion first!')
                _flag_ = False

        if _bflag_ <> None:
            return _flag_
        return max_index
    def autoloadstuff(self):

        nonerr_flag = True

        #_autoload_ = self.objt_c[0].get()
        main_top_file = self.objt_c[2].get()

        if self.autoload_buffer <> main_top_file:
            #    self.autoload_buffer = _autoload_
            self.autoload_buffer = main_top_file
            aux_cont, nonerr_flag = get_ffldfiles(main_top_file)
            if nonerr_flag:
                for i in [2, 3, 4]:
                    nonerr_flag *= check_file(aux_cont[i - 2])
                    self.file_e[i]._entry.delete(0, 'end')
                    self.file_e[i]._entry.insert(0, aux_cont[i - 2])
                    self.file_e[i]._entry.xview_moveto(1)

                    self.file_e[i].setter(0)

                self.objt_c[0] = (1)
            else:
                self.objt_c[0] = (0)
        elif self.objt_c[0] and self.autoload_buffer == main_top_file:
            pop_wrg_1('Autoload already performed for selected top file.',
                      _i_=0)

        if not self.objt_c[0]:
            pop_err_1('Autoload failed!')
            self.autoload_buffer = ''
            self.autol_b.configure(state='disabled')
            for i in [2, 3, 4]:
                self.file_e[i].setter(1)
    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')
Esempio n. 4
0
 def solvastuff(self):
     '''If this point is reached, some button changed '''
     
     _solvation_ = self.objt_c[-1].get()
     if self.sol_buffer <> _solvation_:
         self.sol_buffer = _solvation_
         
         if _solvation_:
             self.solv_b.configure( state = 'normal')
         else:
             pop_wrg_1('You are choosing to not consider solvation.'
                             ,' If some solvent molecules are in the'
                             +' .gro file they will be ignored!', _i_=0)
             self.solv_b.configure( state = 'disabled')
Esempio n. 5
0
def check_file(_in_file_, content=True, string=''):
    '''Check the correctness of the given input file address'''

    flag = False
    try:
        _auxf = open(_in_file_, "r")
        su = 0
        strcheck = False
        if content:
            if string == '':
                for line in _auxf:
                    su += len(line.rstrip('\n'))
            else:
                for line in _auxf:
                    line = line.rstrip('\n')
                    if string in line:
                        strcheck = True

        _auxf.close()

        if content and su == 0 and string == '':
            pop_wrg_1(' File {} is empty -- '.format(_in_file_))
        elif string <> '' and content and not strcheck:
            pop_wrg_1(' Section {} not found in file {} -- '.format(
                string, _in_file_))
        else:
            flag = True

    except IOError:
        pop_wrg_1(' File {} not found -- '.format(_in_file_))
    return flag
Esempio n. 6
0
 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')
Esempio n. 7
0
 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)
Esempio n. 8
0
def get_ffldfiles( _topfile_):
    ''' 
    self explanatory... sub routine to get the force field files
    if they are stated in the top file.
    starts from the top file
    '''
    ff_file = ''
    nonerr_flag = True
    with open( _topfile_, 'r')  as indata:
        for j_line in indata:
            if j_line.startswith('#include'):
                ff_file =  j_line.split('"')[1]
                break
            elif j_line.startswith('[ moleculetype ]'):
                break
    
    root_folder = '/'.join(_topfile_.split('/')[:-1]+[''])
    ff_file = ff_file.lstrip('.').lstrip('/')
    
    if ff_file <> '':
        # if there is at least one itp, lets parse it
        # first seek for further includes itp
        aux_file_cont = [_topfile_, '']
        print '----- Loading :'
        i = 1
        aux_file_cont[i] =  root_folder + ff_file
        print aux_file_cont[i]
        
        root_folder = '/'.join( aux_file_cont[i].split('/')[:-1]+[''])
        try:
            with open( aux_file_cont[i], 'r')  as indata2:
                for k_line in indata2:
                    if k_line.startswith('#include'):
                        i+=1
                        aux_file_cont.append( root_folder+k_line.split('"')[1])
                        print aux_file_cont[i]
                        if i==3:
                            break
                
        except IOError:
            exit('xx/0 Read error 030, file not found!!.\n')
        # the first one is [ defaults ]
        # second nonbonded atomtypes
        # third bonded 
        _directives_ = ['defaults', 'atomtypes', 'bondtypes']
        file_cont = []
        for _di_ in _directives_:
            file_cont.append( seek_for_directive( aux_file_cont, _di_))
            if file_cont[-1] == '':
                pop_wrg_1('Directive ' + _di_ + ' not found!')
                
                if _di_ == _directives_[-1]:
                    file_cont[-1] = file_cont[0] 
                
            else:
                print ('Using :' +file_cont[-1]+' for ' + _di_) 
    else:
        pop_err_1('Force field files #include not found!')
        nonerr_flag *= False
        
    # final check of non error flag
    if nonerr_flag and len(file_cont) < 3 :
        pop_wrg_1('Your structure seems unfamiliar, just ' +
                  '{} itp found.'.format( len(file_cont)) +
                  '\nthe conversion could fail!')
        # Meaning that the directive seeker could not find the correspondin one
        while len(file_cont) < 3:
            file_cont.append( file_cont[-1])
    # a file integrity check should be done outside
    return file_cont, nonerr_flag