<jupyter_start><jupyter_text>CCMAP development ROADMAP Memory leak safe* **VG** : No Valgrind Error in C implementation* **PS** : Python PyMem & XREF safe in ccmapmodule_ file familyAlgorithmJSON encodingINT encoding**CMAP**        |        | Atomic     | Residue     || :------------- | :----------: | -----------: ||  **Single** | OK   | ?   || **Dual**   | ? |  ?  ||        | Atomic     | Residue     || :------------- | :----------: | -----------: ||  **Single** | ?   | ?   || **Dual**   | ? |  ?  |    **LCMAP**    |        | Atomic     | Residue     || :------------- | :----------: | -----------: ||  **Single** | ?   | ?   || **Dual**   | ? |  ?  ||        | Atomic     | Residue     || :------------- | :----------: | -----------: ||  **Single** | ?   | ?   || **Dual**   | ? |  ?  |**ZMAP**|       | Atomic     | Residue     || :------------- | :----------: | -----------: ||  **Single** | ?   | ?   || **Dual**   | ? |  ?  ||        | Atomic     | Residue     || :------------- | :----------: | -----------: ||  **Single** | ?   | ?   || **Dual**   | ? |  ?  |**LZMAP**|        | Atomic     | Residue     || :------------- | :----------: | -----------: ||  **Single** | ?   | ?   || **Dual**   | ? |  ?  ||       | Atomic     | Residue     || :------------- | :----------: | -----------: ||  **Single** | ?   | ?   || **Dual**   | ? |  ?  | Multi-threads performance chart|                | Natoms      | ....     || :------------- | :----------: | -----------: ||  M threads | ms   | ms   ||     .....   | ms |  ms  |<jupyter_code>import sys, json

sys.path.append("/Users/guillaumelaunay/work/tmp/ccmap2/build/lib.macosx-10.9-x86_64-3.8")
import ccmap
import pyproteinsExt.structure.coordinates as PDB

folderTests="/Users/guillaumelaunay/work/tmp/ccmap2/tests"
with open(f"{folderTests}/1A2K_poses_specs_50K.json", "r") as fp:
    inputs = json.load(fp)

inputs.keys()
## LZMAP typical single thread usage
parser = PDB.Parser()
pdbREC = parser.load(file=f"{folderTests}/1A2K_r_u.pdb")
pdbDictREC = pdbREC.atomDictorize
pdbLIG = parser.load(file=f"{folderTests}/1A2K_l_u.pdb")     
pdbDictLIG = pdbLIG.atomDictorize

ccmap.lzmap(pdbDictREC, pdbDictLIG, inputs['euler'][:2], inputs['translation'][:2],   \
            offsetRec = inputs['recOffset'], offsetLig = inputs['ligOffset'], \
             d = 5.0, encode = True )

# Setting input parameters
parser = PDB.Parser()
pdbREC = parser.load(file=f"{folderTests}/demo_receptor.pdb")
pdbDictREC = pdbREC.atomDictorize
pdbLIG = parser.load(file=f"{folderTests}/demo_ligand.pdb")     
pdbDictLIG = pdbLIG.atomDictorize
e  = inputs['euler'][0]
t  = inputs['translation'][0]
d  = 5
ro = inputs['recOffset']
lo = inputs['ligOffset']

# Computing the contact map                    
results = ccmap.lcmap([pdbDictREC for n in range(3000)], [pdbDictLIG for n in range(3000)], d=d, \
                     encode=True)
help(ccmap)
def getCCasString(i, pdbRec, pdbLig):
    recIDs = pdbRec.getResID
    ligIDs = pdbLig.getResID
    
    iRec = int(i/len(ligIDs))
    iLig = i%len(ligIDs)

    return f"{recIDs[iRec]} -- {ligIDs[iLig]}"

def zmapTest(folderTests, inputs, oracle, v=None):
    parser = PDB.Parser()
    pdbREC = parser.load(file=f"{folderTests}/{inputs['receptorFile']}")
    pdbDictREC = pdbREC.atomDictorize
    pdbLIG = parser.load(file=f"{folderTests}/{inputs['ligandFile']}")     
    pdbDictLIG = pdbLIG.atomDictorize

    tests = 0
    for i in range ( len(inputs['euler']) ):
        if v:
            i = v
        e  = inputs['euler'][i]
        t  = inputs['translation'][i]
        d  = 5
        ro = inputs['recOffset']
        lo = inputs['ligOffset']
        #print(e, t)
                         
        x  = ccmap.zmap(pdbDictREC, pdbDictLIG, tuple(e), tuple(t), \
                   offsetRec=tuple(ro), offsetLig=tuple(lo), distance=d, \
                   encode=True, apply=False)
        y  = oracle['oracle'][i]
                         
        diff1 = set(x) - set(y)
        diff2 = set(y) - set(x)
        
        if len(diff1) + len(diff2) > 0:
            print(f"{tests} test WARNING")
            print("Excess in zmap")
            print( "\n".join([getCCasString(cc, pdbREC, pdbLIG) for cc in diff1]), "\n")
            if len(diff2) > 0:
                print("[FATAL] Excess in oracle")
                print( "\n".join([getCCasString(cc, pdbREC, pdbLIG) for cc in diff2]), "\n")
                return x, y
                         
        tests = tests + 1
        if v:
            break
                         
    print(f"{tests} tests successfull")
    return None, None
                         
def lzmapTest(folderTests, inputs, oracle):
                         
    d  = 5
    ro = inputs['recOffset']
    lo = inputs['ligOffset']
                         
    parser = PDB.Parser()
    pdbREC = parser.load(file=f"{folderTests}/{inputs['receptorFile']}")
    pdbDictREC = pdbREC.atomDictorize
    pdbLIG = parser.load(file=f"{folderTests}/{inputs['ligandFile']}")     
    pdbDictLIG = pdbLIG.atomDictorize
    allX = ccmap.lzmap(pdbDictREC, pdbDictLIG, inputs['euler'], inputs['translation'], \
                   offsetRec=ro, offsetLig=lo, distance=d, \
                   encode=True)
                 
    tests = 0
    for x,y in zip(allX, oracle['oracle']):                   
        diff1 = set(x) - set(y)
        diff2 = set(y) - set(x)
        
        if len(diff1) + len(diff2) > 0:
            print(f"{tests} test WARNING")
            print("Excess in zmap")
            print( "\n".join([getCCasString(cc, pdbREC, pdbLIG) for cc in diff1]), "\n")
            if len(diff2) > 0:
                print("[FATAL] Excess in oracle")
                print( "\n".join([getCCasString(cc, pdbREC, pdbLIG) for cc in diff2]), "\n")
                return x, y
                         
        tests = tests + 1
                         
    print(f"{tests} tests successfull")
    return None, None                 
                         
def applyTransform(folderTests, inputs,i, tag="default"):
    parser = PDB.Parser()
    pdbREC = parser.load(file=f"{folderTests}/{inputs['receptorFile']}")
    pdbDictREC = pdbREC.atomDictorize
    pdbLIG = parser.load(file=f"{folderTests}/{inputs['ligandFile']}")     
    pdbDictLIG = pdbLIG.atomDictorize

    e  = inputs['euler'][i]
    t  = inputs['translation'][i]
    d  = 5
    ro = inputs['recOffset']
    lo = inputs['ligOffset']
                         
    x  = ccmap.zmap(pdbDictREC, pdbDictLIG, e, t, \
           offsetRec=tuple(ro), offsetLig=lo, distance=d, \
           encode=True, apply=True)
    pdbREC.setCoordinateFromDictorize(pdbDictREC)
    pdbLIG.setCoordinateFromDictorize(pdbDictLIG)
    with open(f"{folderTests}/{tag}_receptor.pdb", "w") as fp:
        fp.write( str(pdbREC) )
    with open(f"{folderTests}/{tag}ligand.pdb", "w") as fp:
        fp.write( str(pdbLIG) )

    return pdbREC, pdbLIG

def displayCtcs(encodeVec, inputs):
    parser = PDB.Parser()
    pdbREC = parser.load(file=f"{folderTests}/{inputs['receptorFile']}")
    pdbDictREC = pdbREC.atomDictorize
    pdbLIG = parser.load(file=f"{folderTests}/{inputs['ligandFile']}")     
    pdbDictLIG = pdbLIG.atomDictorize
    
    print("Total contacts sel")
    print( "\n".join([getCCasString(cc, pdbREC, pdbLIG) for cc in encodeVec]), "\n")
# Setting input parameters
parser = PDB.Parser()
pdbREC = parser.load(file=f"{folderTests}/demo_receptor.pdb")
pdbDictREC = pdbREC.atomDictorize
pdbLIG = parser.load(file=f"{folderTests}/demo_ligand.pdb")     
pdbDictLIG = pdbLIG.atomDictorize
e  = inputs['euler'][0]
t  = inputs['translation'][0]
d  = 5
ro = inputs['recOffset']
lo = inputs['ligOffset']

# Computing the contact map                    
results = ccmap.lmap([pdbDictREC],d=d, \
                     encode=True)<jupyter_output><empty_output><jupyter_text>Demonstrating bEncode for single two-body PDB  Single call getting integer encode residue-residue contact map<jupyter_code># Setting input parameters
parser = PDB.Parser()
pdbREC = parser.load(file=f"{folderTests}/{inputs['receptorFile']}")
pdbDictREC = pdbREC.atomDictorize
pdbLIG = parser.load(file=f"{folderTests}/{inputs['ligandFile']}")     
pdbDictLIG = pdbLIG.atomDictorize
e  = inputs['euler'][0]
t  = inputs['translation'][0]
d  = 5
ro = inputs['recOffset']
lo = inputs['ligOffset']

# Computing the contact map                    
results = ccmap.zmap(pdbDictREC, pdbDictLIG, e, t, \
                     offsetRec=ro, offsetLig=lo, distance=d, \
                     encode=True)<jupyter_output><empty_output><jupyter_text>Visualize the output with```python print(results)```  Single call getting json-string representation of the residue-residue contact mapNote that setting the *apply* optional attribute to True will modify the passed dictionaries of coordinates. So we can generate the corresponding stuctures.<jupyter_code># Setting input parameters
parser = PDB.Parser()
pdbREC = parser.load(file=f"{folderTests}/{inputs['receptorFile']}")
pdbDictREC = pdbREC.atomDictorize
pdbLIG = parser.load(file=f"{folderTests}/{inputs['ligandFile']}")     
pdbDictLIG = pdbLIG.atomDictorize
e  = inputs['euler'][0]
t  = inputs['translation'][0]
d  = 5
ro = inputs['recOffset']
lo = inputs['ligOffset']

# Computing the contact map  
results = ccmap.zmap(pdbDictREC, pdbDictLIG, e, t, \
                     offsetRec=tuple(ro), offsetLig=lo, distance=d, \
                     encode=False, apply=True)

# Dump the conformation specific PDB files
pdbREC.setCoordinateFromDictorize(pdbDictREC)
pdbLIG.setCoordinateFromDictorize(pdbDictLIG)
with open(f"{folderTests}/demo_receptor.pdb", "w") as fp:
    fp.write( str(pdbREC) )
with open(f"{folderTests}/demo_ligand.pdb", "w") as fp:
    fp.write( str(pdbLIG) )<jupyter_output><empty_output><jupyter_text>Visualize the output with```python print(results)```  No Transformation   Testing bEncode for two-body PDBLet's use the previously generated structures<jupyter_code># Setting input parameters
parser = PDB.Parser()
pdbRECa = parser.load(file=f"{folderTests}/demo_receptor.pdb")
pdbDictRECa = pdbRECa.atomDictorize
pdbLIGa = parser.load(file=f"{folderTests}/demo_ligand.pdb")     
pdbDictLIGa = pdbLIGa.atomDictorize

ccmap.cmap(pdbDictRECa, y=pdbDictLIGa, d=4.5,\
                       atomic=True, encode=True)<jupyter_output>ccmap_compute_flex<jupyter_text>Visualize the output with```python print(results_a)```which should be identical to the previous one  Atomic Contact maps```json{ "type":"atomic", "data" : [] }```Where `"data"` is a json array of 2-uples. Each 2-uple encoding a pair of atom in contact. Atoms are specified as 4 elements array of the shape `[NAME, RESN, RESID, SEGID]`.  Getting the atomic contact map between two bodies<jupyter_code>ccmap.cmap(pdbDictRECa, y=pdbDictLIGa, d=4.5, atomic=True, encode=True)<jupyter_output><empty_output><jupyter_text>Getting the "self" atomic contact map of one body<jupyter_code>results_c = ccmap.cmap(pdbDictRECa, d=4.5, atomic=True)<jupyter_output><empty_output><jupyter_text>Visualize the output with```python print(results_c)```  Getting the  atomic contact map between two bodies<jupyter_code>results_d = ccmap.cmap(pdbDictRECa, y = pdbDictLIGa, d=4.5, atomic=True)<jupyter_output><empty_output><jupyter_text>Visualize the output with```python print(results_c)```<jupyter_code>x, y = lzmapTest(folderTests, inputs, oracle)
pdbRec, pdbLig = applyTransform(folderTests, inputs,1, tag="1A2K_pose_n1")
displayCtcs(x, inputs)
parser = PDB.Parser()
pdbREC = parser.load(file=f"{folderTests}/{inputs['receptorFile']}")
pdbDictREC = pdbREC.atomDictorize
pdbLIG = parser.load(file=f"{folderTests}/{inputs['ligandFile']}")     
pdbDictLIG = pdbLIG.atomDictorize

i  = 0
e  = inputs['euler'][i]
t  = inputs['translation'][i]
d  = 5
ro = inputs['recOffset']
lo = inputs['ligOffset']
                         
x  = ccmap.lzmap(pdbDictREC, pdbDictLIG, [e], [t], \
           offsetRec=ro, offsetLig=lo, distance=d, \
           encode=True)#, apply=True)
x
parser = PDB.Parser()
pdbREC = parser.load(file=f"{folderTests}/{inputs['receptorFile']}")
pdbDictREC = pdbREC.atomDictorize
pdbLIG = parser.load(file=f"{folderTests}/{inputs['ligandFile']}")     
pdbDictLIG = pdbLIG.atomDictorize

i  = 0
e  = inputs['euler'][i]
t  = inputs['translation'][i]
d  = 5
ro = inputs['recOffset']
lo = inputs['ligOffset']
                         
x  = ccmap.lzmap(pdbDictREC, pdbDictLIG, [tuple(e)], [tuple(t)], \
           offsetRec=ro, offsetLig=lo, distance=d, \
           encode=True)
import sys, json

sys.path.append("/Users/guillaumelaunay/work/tmp/ccmap2/build/lib.macosx-10.9-x86_64-3.8")
import ccmap
import pyproteinsExt.structure.coordinates as PDB

folderRoot="/Users/guillaumelaunay/work/tmp/ccmap2/tests"
inputs = json.loads(f"{folderRoot}/poses_specs.json")


e = (-1.9614028226597258, 2.066353592203531, -2.354698828551145)
t = (7.199999999999999, 16.8, 28.799999999999997)
lo = (-67.006, 0.11, -77.27)
ro = (-27.553, -8.229, -80.604)



parser = PDB.Parser()
pdbDictREC = parser.load(file=f"{folderRoot}/1A2K_r_u.pdb").atomDictorize
pdbDictLIG = parser.load(file=f"{folderRoot}/1A2K_l_u.pdb").atomDictorize

pdbDictRECa = parser.load(file=f"{folderRoot}/1A2K_r_u.pdb").atomDictorize
pdbDictLIGb = parser.load(file=f"{folderRoot}/1A2K_l_u.pdb").atomDictorize
for i in range(4):
    d1=ccmap.zmap(pdbDictREC, pdbDictLIG, e, t, offsetRec=list(ro), offsetLig=list(lo), distance=5.0, encode=True, apply=False)
    print(len(d1), ":", d1[0],d1[-1])

d2=ccmap.lzmap(pdbDictRECa, pdbDictLIGb, [e], [t], offsetRec=list(ro), offsetLig=list(lo), distance=5.0, encode=True)
print(len(d2[0]), ":", d2[0][0],d2[0][-1])


pdbDictREC['x'][0]
eList    = [(-1.9614028226597258, 2.066353592203531, -2.354698828551145), (-0.7010661915165238, 0.951968804736611, -0.5323630719195723)]
tList = [(7.199999999999999, 16.8, 28.799999999999997), (21.599999999999998, -7.199999999999999, -20.4)]
ligOffset = [-67.006, 0.11, -77.27]
recOffset = [-27.553, -8.229, -80.604]

import sys, threading

sys.path.append("/Users/guillaumelaunay/work/tmp/ccmap2/build/lib.macosx-10.9-x86_64-3.8")

import json, ccmap
import pyproteinsExt.structure.coordinates as PDB
folderRoot="/Users/guillaumelaunay/work/tmp/ccmap2/data/lzmap"

parser = PDB.Parser()
pdbDictREC = parser.load(file=f"{folderRoot}/1A2K_r_u.pdb").atomDictorize
pdbDictLIG = parser.load(file=f"{folderRoot}/1A2K_l_u.pdb").atomDictorize

with open(f"{folderRoot}/euler_translate_1A2K_1000.json", 'rb') as fp:
    vectors = json.load(fp)
eulers     = [tuple(_) for _ in vectors['euler']]
translations  = [tuple(_) for _ in vectors['translation']]

nThreads = 5
n=200

def lzThread(d, eulers, translations):
    data = ccmap.lzmap(pdbDictREC, pdbDictLIG, eulers[:n], translations[:n], \
            offsetRec=recOffset, offsetLig=ligOffset, distance=d, encode=True)
    return data

dValues= [ 5.0 for i in range(nThreads) ]
threadPool = [threading.Thread(args=(d,), target=lzThread) for d in dValues]



print(f"Starting {nThreads} threads")

for th in threadPool:
    th.start()

for th in threadPool:
    th.join()

    
#th.join()

#results=[None, None, None]
#for i,d in enumerate(dValues):
#    print(i)
 #   results[i] = ccmap.lzmap(pdbDictREC, pdbDictLIG, eulers[:n], translations[:n], \
 #           offsetRec=recOffset, offsetLig=ligOffset, distance=d, encode=True)<jupyter_output>Starting 5 threads
Unpacking 200  euler and translation poses with bEncode:true and D=5.000000
Unpacking 200  euler and translation poses with bEncode:true and D=5.000000
Unpacking 200  euler and translation poses with bEncode:true and D=5.000000
Unpacking 200  euler and translation poses with bEncode:true and D=5.000000
Unpacking 200  euler and translation poses with bEncode:true and D=5.000000<jupyter_text>import syssys.path.append("/Users/guillaumelaunay/work/tmp/ccmap2/build/lib.macosx-10.9-x86_64-3.8") DUMMY TESTpdbDictREC = parser.load(file=f"{folderRoot}/../1a2y_u1_A.pdb").atomDictorizepdbDictLIG = parser.load(file=f"{folderRoot}/../1a2y_u1_A.pdb").atomDictorizeccmap.lzmap(pdbDictREC, pdbDictLIG, [(0.0,0.0,0.0),(0.0,0.0,0.0),(0.0,0.0,0.0)],  [(0.0,0.0,0.0),(0.0,0.0,0.0),(0.0,0.0,0.0)])import ccmapimport pyproteinsExt.structure.coordinates as PDBparser = PDB.Parser()fPdb="/Users/guillaumelaunay/Downloads/1syq.pdb"pdbObj = parser.load(file=fPdb)ccmapInputs = pdbObj.atomDictorizeresidueCCmap = ccmap.cmap(ccmapInputs,y=ccmapInputs)residueCCmapEncoded = ccmap.cmap(ccmapInputs,y=ccmapInputs, encode=True)residueCCmapEncoded<jupyter_code>#residueCCmap<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16884057971014493, 'fraction_numerical': 0.034178743961352655, 'mean_word_length': 3.086109055020972, 'pattern_counts': {'":': 3, '<': 35, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '239809', 'license': 'MIT', 'n_tokens_mistral': 6434, 'n_tokens_neox': 6059, 'n_words': 1074, 'path': 'notebook/ccmap2_DVL.ipynb', 'repo_name': 'MMSB-MOBI/ccmap', 'size': '16560'}