InventMol-R1 is a fine-tuned version of Qwen2.5-0.5B that generates novel drug-like molecules conditioned on biological context. Given a protein target, disease, mutation, and mechanism of action, the model outputs molecular structures in SELFIES format.
This model demonstrates the concept of reasoning-guided molecular ideation aligned with modern AI-driven drug discovery pipelines.
Trained on tyrosine kinase inhibitors with bioactivity data from ChEMBL, filtered for drug-likeness and converted to SELFIES representation. The dataset includes:
1from unsloth import FastLanguageModel
2from selfies import decoder
3from rdkit import Chem
4from rdkit.Chem import Descriptors
5import re
6
7model, tokenizer = FastLanguageModel.from_pretrained("Hamdan003/InventMol-R1")
8
9def extract_selfies(text):
10 matches = re.findall(r'\[[^\]]*\]', text)
11 if len(matches) >= 5:
12 first = text.find(matches[0])
13 count = 0
14 for i in range(first, len(text)):
15 if text[i] == '[': count += 1
16 elif text[i] == ']':
17 count -= 1
18 if count == 0: return text[first:i+1]
19 return ""
20
21def generate_molecule(target, disease, mutation, mechanism):
22 prompt = f"[Target]: {target}\n[Disease]: {disease}\n[Mutation]: {mutation}\n[Mechanism]: {mechanism}\n[Potency]: High\n"
23 inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
24 outputs = model.generate(**inputs, max_new_tokens=300, temperature=0.7, do_sample=True, top_p=0.95)
25 generated = tokenizer.decode(outputs[0], skip_special_tokens=True)
26 selfies_str = extract_selfies(generated)
27 if selfies_str:
28 smiles = decoder(selfies_str)
29 mol = Chem.MolFromSmiles(smiles)
30 if mol:
31 return smiles, Descriptors.MolWt(mol), Descriptors.MolLogP(mol)
32 return None, 0, 0
33
34smiles, mw, logp = generate_molecule("EGFR", "NSCLC", "T790M", "Irreversible covalent inhibition")
35print(f"SMILES: {smiles}\nMW: {mw:.0f}\nLogP: {logp:.1f}")