darkreactions / ESCALATE_report

Transform experimental data into ML ready datasets!
http://escalation.sd2e.org/
MIT License
2 stars 1 forks source link

ECFP4 representation ongoing development #29

Open ipendlet opened 5 years ago

ipendlet commented 5 years ago

def ecpf_binhex(bstr): “”" Convert FROM ECPF4 1024 bit binary string TO hex string, bytewise, preserving leading zeros parameters: bstr (str): ECPF4 fingerprint binary string returns: str: hex represention of binary ECPF4 fingerprint “”"

calculate length of hex string from length of bstr - fwiw bstr often 1024 bits and thus hlen = 256

hlen = (len(bstr) + 3) // 4
# use .format method to convert directly from binary string to hex via int - faster than iterating
return ‘{:0{}x}‘.format(int(bstr, 2), hlen)

def ecpf_hexbin(hstr): “”" Convert FROM ECPF4 hex string [BACK] TO binary string, preserving leading zeros parameters: hstr (str): ECPF4 fingerprint hex string returns: str: binary represention of hex ECPF4 fingerprint “”"

calculate length of binary string from length of hstr - fwiw hstr often 256 chars and thus blen = 1024

# length of hex string - fwiw often 1024 bits
blen = len(hstr) * 4
# use .format method to convert directly from hex string to binary via int - faster than iterating
return ‘{:0{}b}’.format(int(hstr, 16), blen)
ipendlet commented 5 years ago

See attached

ecfp4_hex_io.txt