{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "a1af2321-8860-4a3e-8406-a9ae587b97bf", "metadata": {}, "outputs": [], "source": [ "from transformers import AutoModelForCausalLM, AutoTokenizer\n", "import selfies as sf\n", "from rdkit import Chem\n", "from typing import Optional\n", "import numpy as np\n", "import py3Dmol\n", "from rdkit import Chem, DataStructs\n", "from rdkit.Chem import AllChem\n", "import torch\n", "\n", "def smiles_to_3d(smiles_list, width=400, height=300):\n", " # Visualize the 3D structure using py3Dmol\n", " view = py3Dmol.view(width=width, height=height)\n", " for smiles in smiles_list:\n", " # Generate the RDKit molecule object\n", " mol = Chem.MolFromSmiles(smiles)\n", " if mol is None:\n", " raise ValueError(\"Invalid SMILES string\")\n", "\n", " # Add hydrogens to the molecule\n", " mol = Chem.AddHs(mol)\n", "\n", " # Generate 3D coordinates\n", " AllChem.EmbedMolecule(mol, randomSeed=42)\n", " AllChem.UFFOptimizeMolecule(mol)\n", "\n", " # Generate the 3D structure in the form of a pdb string\n", " pdb = Chem.MolToPDBBlock(mol)\n", " view.addModel(pdb, 'pdb')\n", " view.setStyle({'stick': {}})\n", " view.zoomTo()\n", " return view\n", "\n", " \n", "# Load the checkpoint and the tokenizer\n", "checkpoint_path = \"lamthuy/SelfiesGen\"\n", "model = AutoModelForCausalLM.from_pretrained(checkpoint_path)\n", "tokenizer = AutoTokenizer.from_pretrained(checkpoint_path)" ] }, { "cell_type": "code", "execution_count": 9, "id": "9b7066a4-6637-4d45-a0d9-3cc5e2ca0409", "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.