Ejemplo n.º 1
0
def write_cif(placed_all, fixed_bonds, scaled_params, sc_unit_cell, cifname,
              charges):

    sc_a, sc_b, sc_c, sc_alpha, sc_beta, sc_gamma = scaled_params
    zs = 0.5

    #opath = os.path.join('cifs', cifname)
    opath = cifname

    coords = []
    sps = []
    for l in placed_all:
        vec = list(map(float, l[1:4]))
        cvec = np.dot(np.linalg.inv(sc_unit_cell), vec)
        coord = [
            np.round(cvec[0], 10),
            np.round(cvec[1], 10),
            np.round(cvec[2], 10)
        ]
        coords.append(coord)
        sps.append(re.sub('[0-9]', '', l[0]))
    lat = Lattice.from_parameters(sc_a, sc_b, sc_c, sc_alpha, sc_beta,
                                  sc_gamma)
    st = Structure(lat, sps, coords)
    st.sort()
    min_d = st.distance_matrix + np.eye(len(st)) * 1000
    if min_d.min() < 1.0:
        print("! %s", opath)
        return

    with open(opath, 'w') as out:
        out.write('data_' + cifname[0:-4] + '\n')
        out.write('_audit_creation_date              ' +
                  datetime.datetime.today().strftime('%Y-%m-%d') + '\n')
        out.write("_audit_creation_method            'tobacco_3.0'" + '\n')
        out.write("_symmetry_space_group_name_H-M    'P1'" + '\n')
        out.write('_symmetry_Int_Tables_number       1' + '\n')
        out.write('_symmetry_cell_setting            triclinic' + '\n')
        out.write('loop_' + '\n')
        out.write('_symmetry_equiv_pos_as_xyz' + '\n')
        out.write('  x,y,z' + '\n')
        out.write('_cell_length_a                    ' + str(sc_a) + '\n')
        out.write('_cell_length_b                    ' + str(sc_b) + '\n')
        out.write('_cell_length_c                    ' + str(sc_c) + '\n')
        out.write('_cell_angle_alpha                 ' + str(sc_alpha) + '\n')
        out.write('_cell_angle_beta                  ' + str(sc_beta) + '\n')
        out.write('_cell_angle_gamma                 ' + str(sc_gamma) + '\n')
        out.write('loop_' + '\n')
        out.write('_atom_site_label' + '\n')
        out.write('_atom_site_type_symbol' + '\n')
        out.write('_atom_site_fract_x' + '\n')
        out.write('_atom_site_fract_y' + '\n')
        out.write('_atom_site_fract_z' + '\n')
        if charges:
            out.write('_atom_site_charge' + '\n')
        for l in placed_all:
            vec = list(map(float, l[1:4]))
            cvec = np.dot(np.linalg.inv(sc_unit_cell), vec)
            if charges:
                out.write('{:7} {:>4} {:>15} {:>15} {:>15} {:>15}'.format(
                    l[0], re.sub('[0-9]', '',
                                 l[0]), "%.10f" % (np.round(cvec[0], 10) + zs),
                    "%.10f" % (np.round(cvec[1], 10) + zs),
                    "%.10f" % (np.round(cvec[2], 10) + zs), l[4]))
                out.write('\n')
            else:
                out.write('{:7} {:>4} {:>15} {:>15} {:>15}'.format(
                    l[0], re.sub('[0-9]', '',
                                 l[0]), "%.10f" % (np.round(cvec[0], 10) + zs),
                    "%.10f" % (np.round(cvec[1], 10) + zs),
                    "%.10f" % (np.round(cvec[2], 10) + zs)))
                out.write('\n')

        out.write('loop_' + '\n')
        out.write('_geom_bond_atom_site_label_1' + '\n')
        out.write('_geom_bond_atom_site_label_2' + '\n')
        out.write('_geom_bond_distance' + '\n')
        out.write('_geom_bond_site_symmetry_2' + '\n')
        out.write('_ccdc_geom_bond_type' + '\n')

        for e in fixed_bonds:
            out.write('{:7} {:>7} {:>5} {:>7} {:>3}'.format(
                e[0], e[1], "%.3f" % float(e[2]), e[3], e[4]))
            out.write('\n')
Ejemplo n.º 2
0
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')
s.to('POSCAR', 'CONTCAR')