Skip to content

Instantly share code, notes, and snippets.

@rajarshi
Created July 3, 2022 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajarshi/ff74d3d6b169dbe8c8ca0bf122cc334e to your computer and use it in GitHub Desktop.
Save rajarshi/ff74d3d6b169dbe8c8ca0bf122cc334e to your computer and use it in GitHub Desktop.
import selfies, random, sys
N = 1000
M = 500
selfies.set_semantic_constraints("octet_rule")
alphabet= list(selfies.get_semantic_robust_alphabet())
alphabet = list(filter(lambda x: '+' not in x and '-' not in x, alphabet))
rnd_smi = set()
while len(rnd_smi) < N:
slf = ''.join(random.choices(alphabet, k=M))
smi = selfies.decoder(slf)
if len(smi) > 40:
rnd_smi.add(smi)
sys.stdout.write(f"\rmade {len(rnd_smi)} SMILES")
sys.stdout.flush()
o =open('rnd.smi', 'w')
for i in rnd_smi:
o.write(f"{i}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment