|
我以前用过RDKit中的ETKDGv3功能( https://www.rdkit.org/docs/source/rdkit.Chem.rdDistGeom.html )。这是当时写的从SMILES字符串生成xyz文件的代码,博君一笑。ETKDGv3是自RDKit 2020.03版本引入的。自RDKit 2024.03开始,ETKDGv3成为RDKit中生成构象的默认功能。
- '''
- This script generates xyz files from a SMILES string. This script requires
- RDKit which should be at least version 2020.03. Cite the following paper
- if you use this script in any published work.
- S. Wang, J. Witek, G. A. Landrum, S. Riniker, J. Chem. Inf. Model. 2020, 60(4), 2044–2058
- Generate one conformer for a molecule with the following command:
- python smiles2xyz.py -s "CC(CC1=CC=CC=C1)[N+]2=NOC(=C2)/N=C(/NC3=CC=CC=C3)\[O-]" -c mesocarb
- Generate ten conformers for a molecule with the following command:
- python smiles2xyz.py -s "CC(CC1=CC=CC=C1)[N+]2=NOC(=C2)/N=C(/NC3=CC=CC=C3)\[O-]" -c mesocarb -n 10
- '''
- import sys
- import argparse
- from rdkit import Chem
- from rdkit.Chem import AllChem
- def write_xyz_file(fragment, fragment_name):
- number_of_atoms = fragment.GetNumAtoms()
- symbols = [a.GetSymbol() for a in fragment.GetAtoms()]
- fNames = []
- for i,conf in enumerate(fragment.GetConformers()):
- file_name = fragment_name+"_"+str(i)+".xyz"
- fNames.append(file_name)
- with open(file_name, "w") as file:
- file.write(str(number_of_atoms)+"\n")
- file.write("\n")
- for atom,symbol in enumerate(symbols):
- p = conf.GetAtomPosition(atom)
- line = " ".join((symbol,str(p.x),str(p.y),str(p.z),"\n"))
- file.write(line)
- return fNames
- parser = argparse.ArgumentParser(usage=__doc__)
- parser.add_argument('--string', '-s', required=True, type=str, help='SMILES string')
- parser.add_argument('--compound', '-c', required=True, type=str, help='Compound name, which will be used as the prefix for xyz file')
- parser.add_argument('--number', '-n', default=argparse.SUPPRESS, type=int, help='Number of conformers for a compound')
- args = parser.parse_args()
- mol = Chem.MolFromSmiles(args.string)
- mol_h = Chem.AddHs(mol)
- params = Chem.rdDistGeom.srETKDGv3()
- params.randomSeed = 0xf00d
- params.clearConfs = True
- if 'number' in args:
- if args.number > 0:
- number_of_conformers = args.number
- else:
- print("The argument for number of conformers in the input cannot be used.")
- sys.exit(1)
- else:
- number_of_conformers = 1
- cids = AllChem.EmbedMultipleConfs(mol_h, number_of_conformers, params)
- fn = write_xyz_file(mol_h, args.compound)
复制代码
|
评分 Rate
-
查看全部评分 View all ratings
|