create_caches2.py
def create_cache2(molfiles, data_root, outfile):
    '''Create an outfile molcache2 file from the list molfiles stored at data_root.'''
    out = open(outfile,'wb')
    #first byte is for versioning
    out.write(struct.pack('i',-1))
    out.write(struct.pack('L',0)) #placeholder for offset to keys

    filler = multiprocessing.Process(target=fill_queue,args=(molfiles,))
    filler.start()

   
    readers = multiprocessing.Pool(N)
    for _ in range(N):
      readers.apply_async(read_data,(data_root,))
    
    offsets = dict() #indxed by mol, location of data
    #start writing molecular data
    endcnt = 0
    while True:
        moldata = mols_to_write.get()
        if moldata == None:
           endcnt += 1
           if endcnt == N:
             break
           else:
             continue
        (mol,data) = moldata
        offsets[mol] = out.tell()
        natoms = len(data)//16
        out.write(struct.pack('i',natoms))
        out.write(data)
    
    start = out.tell() #where the names start
    for mol in molfiles:
        if len(mol) > 255:
            print("Skipping",mol,"since filename is too long")
            continue
        if mol not in offsets:
            print("SKIPPING",mol,"since failed to read it in")
            continue
        s = bytes(mol, encoding='UTF-8')
        out.write(struct.pack('B',len(s)))
        out.write(s)
        out.write(struct.pack('L',offsets[mol]))
        
    #now set start
    out.seek(4)
    out.write(struct.pack('L',start))
    out.seek(0,os.SEEK_END)
    out.close()
Create an outfile molcache2 file from the list molfiles stored at data_root.
Create an outfile molcache2 file from the list molfiles stored at data_root.
Create an outfile molcache2 file from the list molfiles stored at data_root .
def create_cache2(molfiles, data_root, outfile):
    out = open(outfile,'wb')
    out.write(struct.pack('i',-1))
    out.write(struct.pack('L',0)) 
    filler = multiprocessing.Process(target=fill_queue,args=(molfiles,))
    filler.start()
    readers = multiprocessing.Pool(N)
    for _ in range(N):
      readers.apply_async(read_data,(data_root,))
    offsets = dict() 
    endcnt = 0
    while True:
        moldata = mols_to_write.get()
        if moldata == None:
           endcnt += 1
           if endcnt == N:
             break
           else:
             continue
        (mol,data) = moldata
        offsets[mol] = out.tell()
        natoms = len(data)//16
        out.write(struct.pack('i',natoms))
        out.write(data)
    start = out.tell() 
    for mol in molfiles:
        if len(mol) > 255:
            print("Skipping",mol,"since filename is too long")
            continue
        if mol not in offsets:
            print("SKIPPING",mol,"since failed to read it in")
            continue
        s = bytes(mol, encoding='UTF-8')
        out.write(struct.pack('B',len(s)))
        out.write(s)
        out.write(struct.pack('L',offsets[mol]))
    out.seek(4)
    out.write(struct.pack('L',start))
    out.seek(0,os.SEEK_END)
    out.close()
def create_cache2 ( molfiles , data_root , outfile ) : out = open ( outfile , 'wb' ) out . write ( struct . pack ( 'i' , - 1 ) ) out . write ( struct . pack ( 'L' , 0 ) ) filler = multiprocessing . Process ( target = fill_queue , args = ( molfiles , ) ) filler . start ( ) readers = multiprocessing . Pool ( N ) for _ in range ( N ) : readers . apply_async ( read_data , ( data_root , ) ) offsets = dict ( ) endcnt = 0 while True : moldata = mols_to_write . get ( ) if moldata == None : endcnt += 1 if endcnt == N : break else : continue ( mol , data ) = moldata offsets [ mol ] = out . tell ( ) natoms = len ( data ) // 16 out . write ( struct . pack ( 'i' , natoms ) ) out . write ( data ) start = out . tell ( ) for mol in molfiles : if len ( mol ) > 255 : print ( "Skipping" , mol , "since filename is too long" ) continue if mol not in offsets : print ( "SKIPPING" , mol , "since failed to read it in" ) continue s = bytes ( mol , encoding = 'UTF-8' ) out . write ( struct . pack ( 'B' , len ( s ) ) ) out . write ( s ) out . write ( struct . pack ( 'L' , offsets [ mol ] ) ) out . seek ( 4 ) out . write ( struct . pack ( 'L' , start ) ) out . seek ( 0 , os . SEEK_END ) out . close ( )
Create an outfile molcache2 file from the list molfiles stored at data_root.
Create an outfile molcache2 file from the list molfiles stored at data_root .
'''Create an outfile molcache2 file from the list molfiles stored at data_root.''' #first byte is for versioning #placeholder for offset to keys #indxed by mol, location of data #start writing molecular data #where the names start #now set start
molfiles
data_root
outfile