Use this file to discover all available pages before exploring further.
ChemAgent can predict the products of chemical reactions (forward synthesis) and suggest reactants needed to synthesize a target molecule (retrosynthesis).
from LLM4Chem.generation import LlaSMolGenerationgenerator = LlaSMolGeneration('osunlp/LlaSMol-Mistral-7B')query = "<SMILES> NC1=CC=C2OCOC2=C1.O=CO </SMILES> Based on the reactants and reagents given above, suggest a possible product."result = generator.generate(query)print(result[0]['output'][0])# Output: A possible product can be <SMILES> O=CNC1=CC=C2OCOC2=C1 </SMILES> .
Reaction SMILES use the format: reactants.reagents>conditions>productFor queries, separate multiple reactants/reagents with dots: reactant1.reactant2.reagent1
query = """What product is formed from the following reaction?<SMILES> CC(=O)OC1=CC=CC=C1C(=O)O.NaOH </SMILES>"""result = generator.generate(query)print(result[0]['output'][0])
query = "Identify possible reactants that could have been used to create the specified product. <SMILES> CC1=CC=C(N)N=C1N </SMILES>"result = generator.generate(query)print(result[0]['output'][0])# Output: <SMILES> CC(C#N)CCC#N.N </SMILES>
For complex molecules, you may need iterative retrosynthesis:
def retrosynthetic_analysis(target_smiles, max_steps=3): """Perform multi-step retrosynthetic analysis""" steps = [] current_target = target_smiles for i in range(max_steps): query = f"What reactants are needed for <SMILES> {current_target} </SMILES>?" result = generator.generate(query) # Extract reactants match = re.search(r'<SMILES>\s*(.+?)\s*</SMILES>', result[0]['output'][0]) if not match: break reactants = match.group(1) steps.append({ 'step': i + 1, 'target': current_target, 'reactants': reactants }) # For next iteration, analyze the most complex reactant # (simplified - just take the first reactant) if '.' in reactants: current_target = reactants.split('.')[0] else: break return steps# Example usagetarget = "CC(=O)OC1=CC=CC=C1C(=O)O" # Aspirinanalysis = retrosynthetic_analysis(target)for step in analysis: print(f"\nStep {step['step']}:") print(f"Target: {step['target']}") print(f"Reactants: {step['reactants']}")
def find_similar_reactions(query_reactants, reaction_database): """Find similar reactions in a database""" # Predict product for query query = f"<SMILES> {query_reactants} </SMILES> Predict the product." result = generator.generate(query) match = re.search(r'<SMILES>\s*(.+?)\s*</SMILES>', result[0]['output'][0]) if not match: return [] query_product = match.group(1) # Search database for similar transformations similar = [] for rxn in reaction_database: if rxn['product'] == query_product: similar.append(rxn) return similar