def setUpClass(cls): # head molecule cls.peo_head = Molecule.from_file(os.path.join(test_dir, "peo_head.xyz")) charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861] cls.peo_head.add_site_property("charge", charges) s_head = 0 s_tail = 5 # chain molecule cls.peo_bulk = Molecule.from_file(os.path.join(test_dir, "peo_bulk.xyz")) charges = [-0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861] cls.peo_bulk.add_site_property("charge", charges) head = 0 tail = 4 # terminal molecule cls.peo_tail = Molecule.from_file(os.path.join(test_dir, "peo_tail.xyz")) charges = [-0.0326, 0.0861, 0.0861, -0.2792, -0.1187, 0.0861, 0.0861, 0.0861] cls.peo_tail.add_site_property("charge", charges) e_head = 0 e_tail = 4 cls.n_units = 25 link_distance = 1.5075 # create the polymer cls.peo_polymer = Polymer( cls.peo_head, s_head, s_tail, cls.peo_bulk, head, tail, cls.peo_tail, e_head, e_tail, cls.n_units, link_distance, ) # linear chain cls.peo_polymer_linear = Polymer( cls.peo_head, s_head, s_tail, cls.peo_bulk, head, tail, cls.peo_tail, e_head, e_tail, cls.n_units, link_distance, linear_chain=True, )
def run_task(self, fw_spec): molecules = self["constituent_molecules"] mols_number = self["mols_number"] input_filename = self["input_filename"] forcefield = self["forcefield"] topologies = self["topologies"] user_settings = self.get("user_settings", {}) data_filename = self.get("data_filename", user_settings.get("data_file", "lammps.data")) final_molecule = self["final_molecule"] # if the final molecule was generated using packmol if fw_spec.get("packed_mol", None): final_molecule = fw_spec["packed_mol"] elif isinstance(final_molecule, six.string_types): final_molecule = Molecule.from_file(final_molecule) #molecules, mols_number, final_molecule lammps_ff_data = LammpsData.from_ff_and_topologies( forcefield, topologies, self["box_size"]) lammps_input_set = LammpsInputSet.from_file( "ff-inputset", self["input_file"], user_settings=user_settings, lammps_data=lammps_ff_data, data_filename=data_filename, is_forcefield=True) lammps_input_set.write_input(input_filename, data_filename)
def import_Structure(type, config): if type == 'xyz': molecule = Molecule.from_file(config['filename']) lattice = Lattice([config["lattice_parameters"]["vectors"]['i'],config["lattice_parameters"]["vectors"]["j"],config["lattice_parameters"]["vectors"]["k"]]) return Structure(lattice, generate_atom_list(molecule.species), generate_coordinate_list(molecule)) else: return None
def test_get_atoms_from_molecule(self): m = Molecule.from_file(os.path.join(test_dir, "acetylene.xyz")) atoms = aio.AseAtomsAdaptor.get_atoms(m) ase_composition = Composition(atoms.get_chemical_formula()) self.assertEqual(ase_composition, m.composition) self.assertTrue(atoms.cell is None or not atoms.cell.any()) self.assertTrue(atoms.get_pbc() is None or not atoms.get_pbc().any())
def run_task(self, fw_spec): molecules = self["constituent_molecules"] mols_number = self["mols_number"] input_filename = self["input_filename"] forcefield = self["forcefield"] topologies = self["topologies"] user_settings = self.get("user_settings", {}) data_filename = self.get("data_filename", user_settings.get("data_file", "lammps.data")) final_molecule = self["final_molecule"] # if the final molecule was generated using packmol if fw_spec.get("packed_mol", None): final_molecule = fw_spec["packed_mol"] elif isinstance(final_molecule, six.string_types): final_molecule = Molecule.from_file(final_molecule) #molecules, mols_number, final_molecule lammps_ff_data = LammpsData.from_ff_and_topologies(forcefield, topologies, self["box_size"]) lammps_input_set = LammpsInputSet.from_file("ff-inputset", self["input_file"], user_settings=user_settings, lammps_data=lammps_ff_data, data_filename=data_filename, is_forcefield=True) lammps_input_set.write_input(input_filename, data_filename)
def run_task(self, fw_spec): molecules = self["constituent_molecules"] mols_number = self["mols_number"] input_filename = self["input_filename"] forcefield = self["forcefield"] topologies = self["topologies"] user_settings = self.get("user_settings", {}) data_filename = user_settings.get("data_file", "lammps.data") final_molecule = self["final_molecule"] if isinstance(final_molecule, six.string_types): final_molecule = Molecule.from_file(final_molecule) lammps_ff_data = LammpsForceFieldData.from_forcefield_and_topology( molecules, mols_number, self["box_size"], final_molecule, forcefield, topologies) lammps_input_set = LammpsInputSet.from_file( "forcefield", self["input_file"], user_settings=user_settings, lammps_data=lammps_ff_data, data_filename=data_filename, is_forcefield=True) lammps_input_set.write_input(input_filename, data_filename)
def get_surface_indices_2(xyz_file, bond_distance): mol = Molecule.from_file(xyz_file) bulk_coordination = 4 surface_i = [] for i in range(len(mol.sites)): neighbors = mol.get_neighbors(mol.sites[i], bond_distance) if len(neighbors) < bulk_coordination: surface_i.append(i) return surface_i
def phase_sol(self, EB_K_2, judge='', appendage=""): import os from pymatgen import Structure from pymatgen.io.vasp.sets import MPRelaxSet from pymatgen import Structure, Lattice, MPRester, Molecule import shutil ass = self.cif_route print(ass) # os.chdir(r"D:\Desktop\VASP practical\Input") # print (os.getcwd()) # Note that you must provide your own API Key, which can # be accessed via the Dashboard at materialsproject.org #mpr = MPRester()#密钥 molecule = Molecule.from_file(ass) structure = molecule.get_boxed_structure(self.a, self.b, self.c) print(structure) os.chdir(r"D:\Desktop\VASP practical\Input") print(os.getcwd()) custom_settings = {"NELMIN": 5} # user custom incar settings relax = MPRelaxSet(structure, user_incar_settings=custom_settings) os.chdir(r"D:\Desktop\VASP practical\Input") print(os.getcwd()) relax.write_input(ass + '---' + "sol" + str(EB_K_2) + 'phase') os.chdir("./" + ass + '---' + "sol" + str(EB_K_2) + 'phase') #定义一个更改当前目录的变量 dire2 = './vaspstd_sub' #确立脚本名称 shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2) eb = str(EB_K_2) #将介电常数参数作为字符串 ls = str('TURE') #加入开启溶剂参数 with open('INCAR', 'a') as file_object: file_object.write('LSOL = ' + ls + '\n' + 'EB_K = ' + eb) #将两个参数写入INCAR eb = appendage #储存WAVECAR with open('INCAR', 'r') as f1: lines = f1.readlines() with open('INCAR', 'w') as f2: for line in lines: if judge in line: continue f2.write(line) with open('INCAR', 'a') as f3: f3.write(eb) os.chdir(r"D:\Desktop\VASP practical\workdir") print(os.getcwd())
def topmost(): m = Molecule.from_file('snapshot4.xyz') for j, i in enumerate(m.sites): if i.z > 26.5 and i.species_string is 'La': m.remove_sites([j]) m.insert(j, Element.Ag, i.coords) if i.z > 25 and i.species_string is 'Al': m.remove_sites([j]) m.insert(j, Element.Mg, i.coords) if i.z > 25 and i.species_string is 'O': m.remove_sites([j]) m.insert(j, Element.N, i.coords) print(m)
def setUpClass(cls): # head molecule cls.peo_head = Molecule.from_file(os.path.join(test_dir, "peo_head.xyz")) charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861] cls.peo_head.add_site_property("charge", charges) s_head = 0 s_tail = 5 # chain molecule cls.peo_bulk = Molecule.from_file(os.path.join(test_dir, "peo_bulk.xyz")) charges = [-0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861] cls.peo_bulk.add_site_property("charge", charges) head = 0 tail = 4 # terminal molecule cls.peo_tail = Molecule.from_file(os.path.join(test_dir, "peo_tail.xyz")) charges = [-0.0326, 0.0861, 0.0861, -0.2792, -0.1187, 0.0861, 0.0861, 0.0861] cls.peo_tail.add_site_property("charge", charges) e_head = 0 e_tail = 4 cls.n_units = 25 link_distance = 1.5075 # create the polymer cls.peo_polymer = Polymer(cls.peo_head, s_head, s_tail, cls.peo_bulk, head, tail, cls.peo_tail, e_head, e_tail, cls.n_units, link_distance) # linear chain cls.peo_polymer_linear = Polymer(cls.peo_head, s_head, s_tail, cls.peo_bulk, head, tail, cls.peo_tail, e_head, e_tail, cls.n_units, link_distance, linear_chain=True)
def setUpClass(cls): ethanol_coords = [[0.00720, -0.56870, 0.00000], [-1.28540, 0.24990, 0.00000], [1.13040, 0.31470, 0.00000], [0.03920, -1.19720, 0.89000], [0.03920, -1.19720, -0.89000], [-1.31750, 0.87840, 0.89000], [-1.31750, 0.87840, -0.89000], [-2.14220, -0.42390, -0.00000], [1.98570, -0.13650, -0.00000]] water_coords = [[9.626, 6.787, 12.673], [9.626, 8.420, 12.673], [10.203, 7.604, 12.673]] cls.ethanol_atoms = ["C", "C", "O", "H", "H", "H", "H", "H", "H"] cls.water_atoms = ["H", "H", "O"] ethanol = Molecule(cls.ethanol_atoms, ethanol_coords) water = Molecule(cls.water_atoms, water_coords) cls.mols = [ethanol, water] cls.cocktail = Molecule.from_file( os.path.join(test_dir, "cocktail.xyz")) cls.packmol_config = [{"number": 1}, {"number": 15}]
def _get_gaussian_ff_top_single(self, filename=None): """ run antechamber using gaussian output file, then run parmchk to generate missing force field parameters. Store and return the force field and topology information in ff_mol. Args: filename: gaussian output file of the molecule Returns: Amberff namedtuple object that contains information on force field and topology """ scratch = tempfile.gettempdir() Amberff = namedtuple("Amberff", ["force_field", "topology"]) with ScratchDir(scratch, copy_from_current_on_enter=True, copy_to_current_on_exit=True) as d: # self._convert_to_pdb(mol, 'mol.pdb') # self.molname = filename.split('.')[0] self._run_antechamber(filename) self._run_parmchk() # if antechamber can't find parameters go to gaff_example.dat try: mol = Molecule.from_file('mol.rtf') print('mol.rtf file exists') except TopCorruptionException: correct_corrupted_top_files('mol.rtf', 'gaff_data.txt') top = Topology.from_file('mol.rtf') print('mol.rtf file does not exist') try: gff = ForceField.from_file('mol.frcmod') except FFCorruptionException: correct_corrupted_frcmod_files('ANTECHAMBER.FRCMOD', 'gaff_data.txt') gff = ForceField.from_file('ANTECHAMBER.FRCMOD') # gff.set_atom_mappings('ANTECHAMBER_AC.AC') # gff.read_charges() # decorate the molecule with the sire property "atomname" #mol.add_site_property("atomname", (list(gff.atom_index.values()))) return Amberff(gff, top)
def phase(self): import os import re from pymatgen import Structure from pymatgen.io.vasp.sets import MPRelaxSet from pymatgen import Structure, Lattice, MPRester, Molecule import shutil ass = self.cif_route print(ass) for dirpath, dirnames, filenames in os.walk(self.cif_route): # print(dirpath) for name in filenames: path = os.path.join(self.cif_route, name) molecule = Molecule.from_file(path) molecule.apply_operation() structure = molecule.get_boxed_structure( self.a, self.b, self.c) os.chdir(r"E:\VASP practical\Input") print(os.getcwd()) structure.make_supercell(self.supercell) custom_settings = {"NELMIN": 5} # user custom incar settings relax = MPRelaxSet(structure, user_incar_settings=custom_settings) os.chdir(r"E:\VASP practical\Input") print(os.getcwd()) relax.write_input(str(name)) os.chdir("./" + str(name)) #定义一个更改当前目录的变量 dire2 = './vaspstd_sub' #确立脚本名称 shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2) os.chdir(r"D:\Desktop\VASP practical\workdir") print(os.getcwd())
def read_structures_from_file(fname): ''' read structure according to filename Args: fname: (str) input filename Returns: structure: Structure obj. or None ''' try: atoms=read(fname) return ase2pmg(atoms) except: try: return Molecule.from_file(fname) except: try: return Structure.from_file(fname) except: print("Parsing error: %s"%fname) return None
def xrd(self, ): import os from pymatgen import Lattice, Structure from pymatgen.analysis.diffraction.xrd import XRDCalculator from IPython.display import Image, display from pymatgen import Structure, Lattice, MPRester, Molecule ass = self.cif_route print(ass) # os.chdir(r"D:\Desktop\VASP practical\Input") # print (os.getcwd()) # Note that you must provide your own API Key, which can # be accessed via the Dashboard at materialsproject.org #mpr = MPRester()#密钥 molecule = Molecule.from_file(ass) structure = molecule.get_boxed_structure(self.a, self.b, self.c) print(structure) os.chdir(r"D:\Desktop\VASP practical\Input") print(os.getcwd()) c = XRDCalculator() c.show_plot(structure) print(os.getcwd())
def setUp(self): self.benzene = Molecule.from_file(os.path.join(test_dir, "benzene.xyz")) self.acetylene = Molecule.from_file(os.path.join(test_dir, "acetylene.xyz"))
def loadSingleMol(path): singleMol = Molecule.from_file(os.path.join(path, 'singlemolecule/singleMol.xyz')) return singleMol
#%% from pymatgen import Structure, Molecule import os os.chdir( '/home/jinho93/new/oxides/perobskite/lanthanum-aluminate/periodic_step/vasp/my015/from-gulp/421/wan/same-nbands/post' ) p = 0 ion = 0 ele = 0 m = Molecule.from_file('wannier90_centres.xyz') s = Structure.from_file('POSCAR') for i in m.sites: # while i.x < 0: # i.x += s.lattice.a # while i.x > s.lattice.a: # i.x -= s.lattice.a # while i.y < 0: # i.y += s.lattice.b # while i.y > s.lattice.b: # i.y -= s.lattice.b while i.z < 0: i.z += s.lattice.c while i.z > s.lattice.c: i.z -= s.lattice.c while i.y < 0: i.y += s.lattice.b while i.y > s.lattice.b: i.y -= s.lattice.b # if i.species_string == 'La':
#%% from pymatgen import Molecule, Structure import os import numpy as np from pymatgen.core.lattice import Lattice os.chdir('/home/jinho93/oxides/perobskite/lanthanum-aluminate/slab/nvt.para.6/island/len-19/step1') s = Molecule.from_file('POSCAR.xyz') sp = [] coords = [] for i in s.sites: if i.x < 7 and i.y < 7: sp.append(i.specie) coords.append(i.coords) new = Structure(Lattice(np.identity(3) * 7.648200),sp, coords, coords_are_cartesian=True) new.to('POSCAR', 'ini_pot/reduced') # %% #%% from pymatgen.command_line.gulp_caller import GulpIO gio = GulpIO() gio.buckingham_input(new, keywords=['conv'], uc=False) # %%
def fix_absorbed(self, need_miller_index, mole, num, selective_dynamic, min_slab_size_1=8.0, min_vacuum_size_1=15, judge='fuchdi', appendage=""): from pymatgen import Structure, Lattice, MPRester, Molecule import pymatgen.core.structure import pymatgen.core.sites from pymatgen.analysis.adsorption import AdsorbateSiteFinder, reorient_z, plot_slab from pymatgen.core.surface import generate_all_slabs from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from matplotlib import pyplot as plt from pymatgen.ext.matproj import MPRester from pymatgen.io.vasp.inputs import Poscar from pymatgen.io.vasp.sets import MVLSlabSet from pymatgen.io.cif import CifWriter import os import shutil from openbabel import openbabel from pymatgen.core.surface import Slab, SlabGenerator, generate_all_slabs, Structure, Lattice, ReconstructionGenerator mp_id = self.mp_id os.chdir(r"F:\VASP practical\Input") print(os.getcwd()) # Note that you must provide your own API Key, which can # be accessed via the Dashboard at materialsproject.org mpr = MPRester() struct = mpr.get_structure_by_material_id(mp_id) struct = SpacegroupAnalyzer( struct).get_conventional_standard_structure() # fcc_ni = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni", "Ni"], # [[0, 0, 0], [0.5, 0.5, 0.5]]) slab = SlabGenerator(struct, miller_index=need_miller_index, min_slab_size=min_slab_size_1, min_vacuum_size=min_vacuum_size_1, center_slab=True) for n, slabs in enumerate(slab.get_slabs()): if str(n) in str(num): slabs_bak = slabs.copy() #可能的晶面 slabs.make_supercell(self.supercell) print(n) #晶胞扩充 asf_ni_111 = AdsorbateSiteFinder( slabs, selective_dynamics=selective_dynamic) ads_sites = asf_ni_111.find_adsorption_sites() # print(ads_sites) assert len(ads_sites) == 4 fig0 = plt.figure() ax = fig0.add_subplot(111) plot_slab(slabs, ax, adsorption_sites=False) fig1 = plt.figure() ax = fig1.add_subplot(111) os.chdir(r"D:\Desktop\VASP practical\Cif library") print(os.getcwd()) obConversion = openbabel.OBConversion() obConversion.SetInAndOutFormats("pdb", "gjf") mol = openbabel.OBMol() print(mol) c = obConversion.ReadFile(mol, "CH3OH.pdb") obConversion.WriteFile(mol, "CH3OH.pdb" + '1.gjf') adsorbate = Molecule.from_file("CH3OH.pdb" + '.gjf') os.chdir(r"F:\VASP practical\Input") print(os.getcwd()) print(adsorbate.sites) ads_structs = asf_ni_111.add_adsorbate( adsorbate, (20, 20, 20), translate=False, ) # ads_structs = asf_ni_111.generate_adsorption_structures(adsorbate, # repeat=[1, 1, 1]) # A = Poscar(ads_structs[0]) A = Poscar(reorient_z(ads_structs)) #将切面转换为Poscar open('POSCAR', 'w').write(str(A)) p = Poscar.from_file('POSCAR') # w = CifWriter(A.struct) # w.write_file('mystructure.cif') path = r'F:\VASP practical\Input\POSCAR' # 文件路径 if os.path.exists(path): # 如果文件存在 # 删除文件,可使用以下两种方法。 os.remove(path) #os.unlink(path) else: print('no such file:%s' % my_file) # 则返回文件不存在 # w = CifWriter(A.struct) # w.write_file('mystructure.cif') relax = p.structure #将Poscar 转换为结构信息 custom_settings = {"NPAR": 4} # 用户的INCAR 设置 relaxs = MVLSlabSet(relax, user_incar_settings=custom_settings) # Vasp输入文件生成器 dire = str(mp_id) + str(selective_dynamic) + str(mole) + str( need_miller_index).replace(" ", "") + str(n) # print (relax) relaxs.write_input(dire) os.chdir("./" + dire) print(os.getcwd()) fig0.savefig('slab.png', bbox_inches='tight', transparent=True, dpi=600, format='png') plot_slab(ads_structs, ax, adsorption_sites=False, decay=0.09) fig1.savefig('slab_adsobate.png', bbox_inches='tight', transparent=True, dpi=600, format='png') #定义一个更改当前目录的变量 dire2 = './vaspstd_sub' #确立脚本名称 shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2) eb = appendage #添加其他INCAR参数 with open('INCAR', 'r') as f1: lines = f1.readlines() with open('INCAR', 'w') as f2: for line in lines: if judge in line: continue f2.write(line) with open('INCAR', 'a') as f3: f3.write(eb) # open('POSCAR001', 'w').write(str(Poscar(reorient_z(ads_structs[0])))) os.chdir(r"D:\Desktop\VASP practical\workdir") print(os.getcwd()) print('finished') # my_lattace = Lattace('mp-698074')#半水石膏 # # my_lattace.phase_out()#生成晶胞优化的输入文件 # go = my_lattace.phase_sol(66,judge='LWAVE', appendage= '\nLWAVE = Ture') # print('yoo')
import os import numpy as np from pymatgen import Molecule os.chdir('/home/jinho93/oxides/perobskite/lanthanum-aluminate/periodic_step/gulp/2.100/2.conf') h = Molecule.from_file('head.xyz') t = Molecule.from_file('300k/tail.xyz') rms = np.array([np.sqrt(np.mean(y**2)) for y in (t.cart_coords - h.cart_coords)]) g = open('reg.xyz', 'w') oxygen_list = np.array(range(540))[rms > 1.] oxygen_list += 2 with open('lao.xyz') as f: for i in range(200): for j in range(542): if j in oxygen_list: tmp = f.readline() tmp = tmp.replace('O', 'F') g.write(tmp) else: g.write(f.readline()) g.close()
def test_get_molecule(self): m = Molecule.from_file(os.path.join(test_dir, "acetylene.xyz")) atoms = aio.AseAtomsAdaptor.get_atoms(m) self.assertEqual( aio.AseAtomsAdaptor.get_molecule(atoms).formula, "H2 C2")
from pymatgen import Molecule import os import numpy as np import operator import collections def prettyPrint(pdict): for key, val in pdict.items(): print(key, ":", val) # this should be part of the workflow ref atomList = ['Si', 'C', 'P', 'N', 'S', 'O'] origin = Molecule.from_file('./data/mol2mol/centermol.xyz') target = Molecule.from_file('./data/mol2mol/targetmol.xyz') transVec = target.center_of_mass - origin.center_of_mass eleCountDict = collections.OrderedDict() for ele in list(set(origin.species)): if origin.species.count(ele) == 1: eleCountDict[ele] = origin.species.count(ele) def getMolVec(mol, singAtomDict): molVec = np.array([]) # list of index indicating those atoms used in building the vector indexVecList = list() for key in singAtomDict.keys():
print(pymatgen.__file__) # In[3]: import sys print(sys.version) # ### Trabalhando com moléculas # In[4]: from pymatgen import Molecule # In[5]: water = Molecule.from_file("water.xyz") print(water) # In[6]: print(water[0]) # In[7]: print(water[1]) # In[8]: print(water[2]) # In[9]:
""" import pymatgen.io.vasp.outputs filename = '/Users/jiedeng/Documents/tmp/jd848/project_folder/pv+hf/3k/solid0/r3/cont1/recal/OUTCAR' out=pymatgen.io.vasp.outputs.Outcar(filename) import pymatgen.io.xyz xyz = '/Users/jiedeng/Documents/tmp/jd848/project_folder/pv+hf/3k/solid0/r3/cont1/recal/asap/ASAP-desc.xyz' file=pymatgen.io.xyz.XYZ(xyz) file=pymatgen.io.xyz.XYZ() from pymatgen import Lattice, Structure, Molecule file = Molecule.from_file(xyz) struct.get_neighbor_list(r=2, sites = struct[:32]) # no detailed info which site corresponds to which struct.get_neighbor_list(r=2, sites = struct[:2]) # no detailed info which site corresponds to which struct=Structure.from_file('/Users/jiedeng/Documents/tmp/jd848/project_folder/pv+hf/3k/solid0/r3/cont1/CONTCAR') import pymatgen.analysis.local_env brunnernn = pymatgen.analysis.local_env.BrunnerNN_real() brunnernn.get_nn_info(struct,1)
task_geo = WritegaussianGeoTask() task_geo_dbinsert = GaussianGeomOptDBInsertionTask() task_freq_esp = WritegaussianFreqESPTask() task_freq_esp_dbinsert = GaussianFreqESPDBInsertionTask() task_lammps_inp = WritelammpsInputTask() task_lammps_log_dbinsert = WritelammpsOutputTask() task_lammps_prop_dbinsert = ParselammpsProperties() coords = [] sp = [] solvent_molecules_path = os.path.join(rubicon.__path__[0], 'workflows/test_mols/test_lammps') moleculelist = glob.glob(solvent_molecules_path + '/*.pdb') for filename in moleculelist: mol = Molecule.from_file(filename) file_name = os.path.basename(filename) mol_with_site_prop = Molecule( mol.species, mol.cart_coords, site_properties={ "mol_name": [os.path.splitext(file_name)[0]] * len(mol.cart_coords) }) fw1 = Firework( [task_geo], name='Gaussian geometry optimization', spec={ "molecule": mol, "mol_name": os.path.splitext(file_name)[0], "charge": 0,
import matplotlib.pyplot as plt import os mole = False os.chdir( '/home/jinho93/oxides/perobskite/lanthanum-aluminate/periodic_step/vasp/from-100/' ) # os.chdir('/home/jinho93/oxides/wurtzite/zno/cp2k/1.aimd/3.16A/30/3.fix') if mole: from pymatgen import Molecule s = Molecule.from_file('tail.xyz') s2 = Molecule.from_file('113th.xyz') else: from pymatgen import Structure s = Structure.from_file('POSCAR') s2 = Structure.from_file('ini/POSCAR') x = [] y = [] fx = [] fy = [] for site, site2 in zip(s.sites, s2.sites): if site.species_string == 'O': x.append(site.y) y.append(site.z) fx.append(site.y - site2.y) fy.append(site.z - site2.z) if site.c < 0.305: print(site.z, site2.z) # fig = plt.figure(figsize=(5.46, 8.56))
#%% import math from pymatgen import Structure, Molecule, Lattice import os os.chdir( '/home/jinho93/oxides/perobskite/lanthanum-aluminate/slab/gulp/nonstochio/La-vac/two' ) m = Molecule.from_file('tail.xyz') l = Lattice.from_lengths_and_angles([11.46615, 15.2882, 50], [90, 90, 90]) s = Structure(l, m.species, m.cart_coords, coords_are_cartesian=True) s.make_supercell([[4, 0, 0], [0, 3, 0], [0, 0, 1]]) s.make_supercell([[1, 1, 0], [1, -1, 0], [0, 0, 1]]) s.sort() # ll = Lattice.from_lengths_and_angles([s.lattice.a / 2, s.lattice.b / 2, s.lattice.c], s.lattice.angles) ll = Lattice.from_lengths_and_angles(s.lattice.abc, s.lattice.angles) s = Structure(ll, s.species, s.cart_coords, coords_are_cartesian=True) indi = [] for i, site in enumerate(s.sites): if site.x + site.y < ll.b / math.sqrt(2): indi.append(i) # s.remove_sites(indi) # s = Structure(ll, s.species, s.cart_coords, coords_are_cartesian=True) # s.to('POSCAR', 'POSCAR')
results = {} for i, s in enumerate(struct.sites): neighbor_list = [] neighbor_data = struct.get_neighbors(s, r_cut, include_index=True) for n in neighbor_data: neighbor_list.append(n[2]) results[i] = neighbor_list return results folder = "/Users/dchannah/work/NU/melt_cdse/traj/split/si_converted/" # f = sys.argv[1] # print particle[0] temps = ["400"] frames = ["1", "2", "3", "4", "5", "6", "7", "8"] for t in temps: bin_dict = {} for u_bs in [10, 15, 20, 25, 35]: bin_dict[u_bs] = [] for f in frames: fil = folder + t + "_" + f + ".xyz" particle = Molecule.from_file(fil) for r_bin in ([0, 10], [10, 15], [15, 20], [20, 25], [25, 35]): lower_bound = r_bin[0] upper_bound = r_bin[1] atom_indices = get_i_in_shell(particle, lower_bound, upper_bound) shell = get_ordering_for_sites(particle, atom_indices) bin_dict[upper_bound].append(np.average(shell)) for u_bs in [10, 15, 20, 25, 35]: print u_bs, str(np.average(bin_dict[u_bs]))
def test_featurize(): """Test the featurization wrapper function.""" structure = Structure.from_file( os.path.join(THIS_DIR, "..", "..", "examples", "structures", "BaO2_mp-1105_computed.cif")) x, indices, names = featurize(structure) # pylint: disable=invalid-name assert len(x) == len(indices) == len(names) == 2 assert indices[0] == 0 assert indices[1] == 1 structure = Structure.from_file( os.path.join(THIS_DIR, "..", "..", "examples", "structures", "Mg_MOF_74.cif")) x, indices, names = featurize(structure) # pylint: disable=invalid-name assert len(x) == len(indices) == len(names) == 6 assert indices[0] == 0 assert indices[1] == 1 structure = Structure.from_file( os.path.join(THIS_DIR, "..", "structure_data_files", "RSM0027.cif")) x, indices, names = featurize(structure) # pylint: disable=invalid-name assert len(x) == len(indices) == len(names) == 2 spga = SpacegroupAnalyzer(structure) spga = SpacegroupAnalyzer(structure) x, indices, names = featurize( # pylint: disable=invalid-name spga.get_primitive_standard_structure()) assert len(x) == len(indices) == len(names) == 2 x, indices, names = featurize( # pylint: disable=invalid-name spga.get_conventional_standard_structure()) assert len(x) == len(indices) == len(names) == 4 structure = Structure.from_file( os.path.join(THIS_DIR, "..", "structure_data_files", "RSM0099.cif")) x, indices, names = featurize(structure) # pylint: disable=invalid-name assert len(x) == len(indices) == len(names) == 3 spga = SpacegroupAnalyzer(structure) x, indices, names = featurize( # pylint: disable=invalid-name spga.get_primitive_standard_structure()) # pylint: disable=invalid-name assert len(x) == len(indices) == len(names) == 3 x, indices, names = featurize( # pylint: disable=invalid-name spga.get_conventional_standard_structure()) assert len(x) == len(indices) == len(names) == 9 # Test Daniele's xyz file m = Molecule.from_file( # pylint: disable=invalid-name os.path.join(THIS_DIR, "..", "structure_data_files", "TSS03_structuredata.xyz")) lattice = np.array([ [6.4214088758454, 0.0, -2.0278718029537], [-1.7281031033172, 9.4571070308166, -5.4721686991526], [0.0, 0.0, 11.18087355], ]) s = Structure(lattice, [s.specie for s in m], m.cart_coords) # pylint: disable=invalid-name x, indices, names = featurize(s) # pylint: disable=invalid-name assert len(x) == len(indices) == len(names) == 2 assert indices[0] == 0 assert indices[1] == 1
def test_get_molecule(self): m = Molecule.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "acetylene.xyz")) atoms = aio.AseAtomsAdaptor.get_atoms(m) self.assertEqual(aio.AseAtomsAdaptor.get_molecule(atoms).formula, "H2 C2")