#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ convert SMILES to xyz """ import sys from openbabel import pybel import numpy as np import ase import ase.io from ase import Atoms from ase.constraints import FixAtoms smiles, out_name = sys.argv[1:3]
''' Introduction to SMILES: https://en.wikipedia.org/wiki/Simplified_molecular-input_line-entry_system https://www.daylight.com/dayhtml/doc/theory/theory.smiles.html '''
## Use openbabel to convert SMILES to xyz. mol = pybel.readstring("smi", smiles) mol.make3D(forcefield='mmff94', steps=100) # mol.write("xyz", filename=out_name+'_pybel.xyz', overwrite=True)
# USE ase to make POSCAR ''' https://wiki.fysik.dtu.dk/ase/ase/atoms.html''' geo = Atoms() geo.set_cell(np.array([[16.0, 0.0, 0.0],[0.0, 17.0, 0.0],[0.0, 0.0, 18.0]])) geo.set_pbc((True,True,True)) for atom in mol: atom_type = atom.atomicnum atom_position = np.array([float(i) for i in atom.coords]) geo.append(atom_type) geo.positions[-1] = atom_position geo.center()
'''https://wiki.fysik.dtu.dk/ase/ase/constraints.html''' c = FixAtoms(indices=[atom.index for atom in geo if atom.symbol == 'XX']) geo.set_constraint(c)
1 geo = Atoms() 2 geo.set_cell(np.array([[16.0, 0.0, 0.0],[0.0, 17.0, 0.0],[0.0, 0.0, 18.0]])) 3 geo.set_pbc((True,True,True)) 4for atom in mol: 5 atom_type = atom.atomicnum 6 atom_position = np.array([float(i) for i in atom.coords]) 7 geo.append(atom_type) 8 geo.positions[-1] = atom_position 9 geo.center()
'''https://wiki.fysik.dtu.dk/ase/ase/constraints.html''' 10 c = FixAtoms(indices=[atom.index for atom in geo if atom.symbol == 'XX']) 11 geo.set_constraint(c)