frag_pele/PlopRotTemp_S_2017/template/templateBuilder.py
def search_and_replace(file, to_search):
      """
        Search and replace atom_names for numbers
      """
      to_replace = range(1, len(to_search)+1)

      with open(file, "r+") as f:
        lines = f.readlines()
        for i, line in enumerate(lines):
          lines[i] = ' ' + line.strip('\n')


      with open(file, "w") as f:
        f.write('\n'.join(lines))
      
      with open(file, "r") as f:
        filedata = f.read()
     

      for (item_to_search, item_to_replace) in zip(to_search, to_replace):
          filedata = filedata.replace(' ' + item_to_search.strip('_')+' ', ' '+str(item_to_replace)+' ') #atom types are like _O1_ (strip)



      f = open(file,'w')
      f.write(filedata)
      f.close()

        Search and replace atom_names for numbers
      
Search and replace atom_names for numbers
Search and replace atom_names for numbers
def search_and_replace(file, to_search):
      to_replace = range(1, len(to_search)+1)
      with open(file, "r+") as f:
        lines = f.readlines()
        for i, line in enumerate(lines):
          lines[i] = ' ' + line.strip('\n')
      with open(file, "w") as f:
        f.write('\n'.join(lines))
      with open(file, "r") as f:
        filedata = f.read()
      for (item_to_search, item_to_replace) in zip(to_search, to_replace):
          filedata = filedata.replace(' ' + item_to_search.strip('_')+' ', ' '+str(item_to_replace)+' ') 
      f = open(file,'w')
      f.write(filedata)
      f.close()
def search_and_replace ( file , to_search ) : to_replace = range ( 1 , len ( to_search ) + 1 ) with open ( file , "r+" ) as f : lines = f . readlines ( ) for i , line in enumerate ( lines ) : lines [ i ] = ' ' + line . strip ( '\n' ) with open ( file , "w" ) as f : f . write ( '\n' . join ( lines ) ) with open ( file , "r" ) as f : filedata = f . read ( ) for ( item_to_search , item_to_replace ) in zip ( to_search , to_replace ) : filedata = filedata . replace ( ' ' + item_to_search . strip ( '_' ) + ' ' , ' ' + str ( item_to_replace ) + ' ' ) f = open ( file , 'w' ) f . write ( filedata ) f . close ( )
Search and replace atom_names for numbers
Search and replace atom_names for numbers
"""
        Search and replace atom_names for numbers
      """ #atom types are like _O1_ (strip)
file
to_search