Exemple #1
0
def test_atomic_2D():
    global outstructs
    global outstrings
    print(
        "=== Testing generation of atomic 2D crystals. This may take some time. ==="
    )
    from time import time
    from pyxtal.symmetry import Group
    from pyxtal.crystal import random_crystal_2D
    from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

    slow = []
    failed = []
    print("  Layer group # |     Symbol    |  Time Elapsed")
    skip = []
    for sg in range(1, 81):
        if sg not in skip:
            g = Group(sg, dim=2)
            multiplicity = len(g[0])  # multiplicity of the general position
            start = time()
            rand_crystal = random_crystal_2D(sg, ["C"], [multiplicity], 4.0)
            end = time()
            timespent = np.around((end - start), decimals=2)
            t = str(timespent)
            if len(t) == 3:
                t += "0"
            t += " s"
            if timespent >= 1.0:
                t += " ~"
            if timespent >= 3.0:
                t += "~"
            if timespent >= 10.0:
                t += "~"
            if timespent >= 60.0:
                t += "~"
                slow.append(sg)
            if rand_crystal.valid:
                if check_struct_group(rand_crystal, sg, dim=2):
                    pass
                else:
                    t += " xxxxx"
                    outstructs.append(rand_crystal.struct)
                    outstrings.append(str("atomic_2D_" + str(sg) + ".vasp"))
                symbol = g.symbol
                print("\t" + str(sg) + "\t|\t" + symbol + "\t|\t" + t)
            else:
                print("~~~~ Error: Could not generate layer group " + str(sg) +
                      " after " + t)
                failed.append(sg)
    if slow != []:
        print(
            "~~~~ The following layer groups took more than 60 seconds to generate:"
        )
        for i in slow:
            print("     " + str(i))
    if failed != []:
        print("~~~~ The following layer groups failed to generate:")
        for i in failed:
            print("     " + str(i))
Exemple #2
0
def random_structure_group(symbols,
                           composition,
                           thickness,
                           tol_factor,
                           model_file,
                           dmin=2.0,
                           Natt=RANDOM_ATTEMPTS):
    # returns pyxtal generated structure (ase Atoms) with lowest e_tot according to megnet model
    tol_m_1 = Tol_matrix(prototype="atomic", factor=tol_factor)
    adapt = AseAtomsAdaptor()
    model = MEGNetModel.from_file(model_file)
    e_tot_min = 0.

    for i in range(Natt):
        group_id = randrange(80) + 1
        my_crystal = random_crystal_2D(group_id,
                                       symbols,
                                       composition,
                                       1.0,
                                       thickness=thickness,
                                       tm=tol_m_1)
        flag = 0
        if my_crystal.valid == True:
            struct = crystal_to_atoms(my_crystal)
            Nat = len(struct.get_chemical_symbols())
            struct_pymatgen = adapt.get_structure(struct)
            try:
                e_tot = model.predict_structure(struct_pymatgen)
            except:
                e_tot = 0.
                print("isolated molecule exception handled")
            struct2x2x1 = struct * (2, 2, 1)
            positions = struct2x2x1.get_positions()
            # positions = struct.get_positions()
            # print(struct)
            flag = check_dist(Nat * 2 * 2, positions, dmin)
            # print(flag)

            if (e_tot < e_tot_min) and flag == 1:
                struct_out = struct
                e_tot_min = e_tot

    print("e_tot/atom: " + str(e_tot_min))
    # write(filename="POSCAR.best.in", images=struct_out, format="espresso-in")
    # write(filename="POSCAR.best", images=struct_out, format="vasp")

    del model

    return struct_out
Exemple #3
0
def get_random_structure(elem, num_atom, sg, dim, thickness=0):
    max_try = 100
    factor = 1.0
    i = 0
    while i < max_try:
        random.seed(time.time() * 1e8)
        if sg == 0:
            sg = get_random_spg(dim)
        symbol, sg = get_symbol_and_number(sg, dim)
        if dim == 3:
            rand_crystal = random_crystal(sg, elem, num_atom, factor)
        elif dim == 2:
            rand_crystal = random_crystal_2D(sg, elem, num_atom, thickness,
                                             factor)
        elif dim == 1:
            rand_crystal = random_crystal_1D(sg, elem, num_atom, thickness,
                                             factor)
        if dim == 0:
            rand_crystal = random_cluster(sg, elem, num_atom, factor)
        if rand_crystal.valid:
            comp = str(rand_crystal.struct.composition)
            comp = comp.replace(" ", "")
            if dim > 0:
                outpath = comp + '.cif'
                CifWriter(rand_crystal.struct,
                          symprec=0.1).write_file(filename=outpath)
                ans = get_symmetry_dataset(rand_crystal.spg_struct,
                                           symprec=1e-1)['international']
                print('Symmetry requested: {:d}({:s}), generated: {:s}'.format(
                    sg, symbol, ans))
                return True
            else:
                outpath = comp + '.xyz'
                rand_crystal.to_file(filename=outpath, fmt='xyz')
                ans = PointGroupAnalyzer(rand_crystal.molecule).sch_symbol
                print('Symmetry requested: {:d}({:s}), generated: {:s}'.format(
                    sg, symbol, ans))
                return True

        i += 1
Exemple #4
0
def test_modules():
    print("====== Testing functionality for pyXtal version 0.1dev ======")

    global failed_package
    failed_package = False  # Record if errors occur at any level

    reset()

    print("Importing sys...")
    try:
        import sys

        print("Success!")
    except Exception as e:
        fail(e)
        sys.exit(0)

    print("Importing numpy...")
    try:
        import numpy as np

        print("Success!")
    except Exception as e:
        fail(e)
        sys.exit(0)

    I = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

    print("Importing pymatgen...")
    try:
        import pymatgen

        print("Success!")
    except Exception as e:
        fail(e)
        sys.exit(0)

    try:
        from pymatgen.core.operations import SymmOp
    except Exception as e:
        fail(e)
        sys.exit(0)

    print("Importing pandas...")
    try:
        import pandas

        print("Success!")
    except Exception as e:
        fail(e)
        sys.exit(0)

    print("Importing spglib...")
    try:
        import spglib

        print("Success!")
    except Exception as e:
        fail(e)
        sys.exit(0)

    print("Importing openbabel...")
    try:
        import ase

        print("Success!")
    except:
        print(
            "Error: could not import openbabel. Try reinstalling the package.")

    print("Importing pyxtal...")
    try:
        import pyxtal

        print("Success!")
    except Exception as e:
        fail(e)
        sys.exit(0)

    print("=== Testing modules ===")

    # =====database.element=====
    print("pyxtal.database.element")
    reset()
    try:
        import pyxtal.database.element
    except Exception as e:
        fail(e)

    print("  class Element")
    try:
        from pyxtal.database.element import Element
    except Exception as e:
        fail(e)
    if passed():
        for i in range(1, 95):
            if passed():
                try:
                    ele = Element(i)
                except:
                    fail("Could not access Element # " + str(i))
                try:
                    y = ele.sf
                    y = ele.z
                    y = ele.short_name
                    y = ele.long_name
                    y = ele.valence
                    y = ele.valence_electrons
                    y = ele.covalent_radius
                    y = ele.vdw_radius
                    y = ele.get_all(0)
                except:
                    fail("Could not access attribute for element # " + str(i))
                try:
                    ele.all_z()
                    ele.all_short_names()
                    ele.all_long_names()
                    ele.all_valences()
                    ele.all_valence_electrons()
                    ele.all_covalent_radii()
                    ele.all_vdw_radii()
                except:
                    fail("Could not access class methods")

    check()

    # =====database.hall=====
    print("pyxtal.database.hall")
    reset()
    try:
        import pyxtal.database.hall
    except Exception as e:
        fail(e)

    print("  hall_from_hm")
    try:
        from pyxtal.database.hall import hall_from_hm
    except Exception as e:
        fail(e)

    if passed():
        for i in range(1, 230):
            if passed():
                try:
                    hall_from_hm(i)
                except:
                    fail("Could not access hm # " + str(i))

    check()

    # =====database.collection=====
    print("pyxtal.database.collection")
    reset()
    try:
        import pyxtal.database.collection
    except Exception as e:
        fail(e)

    print("  Collection")
    try:
        from pyxtal.database.collection import Collection
    except Exception as e:
        fail(e)

    if passed():
        for i in range(1, 230):
            if passed():
                try:
                    molecule_collection = Collection("molecules")
                except:
                    fail("Could not access hm # " + str(i))

    check()

    # =====operations=====
    print("pyxtal.operations")
    reset()
    try:
        import pyxtal.operations
    except Exception as e:
        fail(e)

    print("  random_vector")
    try:
        from pyxtal.operations import random_vector
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in range(10):
                random_vector()
        except Exception as e:
            fail(e)

    check()

    print("  angle")
    try:
        from pyxtal.operations import angle
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in range(10):
                v1 = random_vector()
                v2 = random_vector()
                angle(v1, v2)
        except Exception as e:
            fail(e)

    check()

    print("  random_shear_matrix")
    try:
        from pyxtal.operations import random_shear_matrix
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in range(10):
                random_shear_matrix()
        except Exception as e:
            fail(e)

    check()

    print("  is_orthogonal")
    try:
        from pyxtal.operations import is_orthogonal
    except Exception as e:
        fail(e)

    if passed():
        try:
            a = is_orthogonal([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
            b = is_orthogonal([[0, 0, 1], [1, 0, 0], [1, 0, 0]])
            if a is True and b is False:
                pass
            else:
                fail()
        except Exception as e:
            fail(e)

    check()

    print("  aa2matrix")
    try:
        from pyxtal.operations import aa2matrix
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in range(10):
                aa2matrix(1, 1, random=True)
        except Exception as e:
            fail(e)

    check()

    print("  matrix2aa")
    try:
        from pyxtal.operations import matrix2aa
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in range(10):
                m = aa2matrix(1, 1, random=True)
                aa = matrix2aa(m)
        except Exception as e:
            fail(e)

    check()

    print("  rotate_vector")
    try:
        from pyxtal.operations import rotate_vector
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in range(10):
                v1 = random_vector()
                v2 = random_vector()
                rotate_vector(v1, v2)
        except Exception as e:
            fail(e)

    check()

    print("  are_equal")
    try:
        from pyxtal.operations import are_equal
    except Exception as e:
        fail(e)

    if passed():
        try:
            op1 = SymmOp.from_xyz_string("x,y,z")
            op2 = SymmOp.from_xyz_string("x,y,z+1")
            a = are_equal(op1, op2, PBC=[0, 0, 1])
            b = are_equal(op1, op2, PBC=[1, 0, 0])
            if a is True and b is False:
                pass
            else:
                fail()
        except Exception as e:
            fail(e)

    check()

    print("  class OperationAnalyzer")
    try:
        from pyxtal.operations import OperationAnalyzer
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in range(10):
                m = aa2matrix(1, 1, random=True)
                t = random_vector()
                op1 = SymmOp.from_rotation_and_translation(m, t)
                OperationAnalyzer(op1)
        except Exception as e:
            fail(e)

    check()

    print("  class Orientation")
    try:
        from pyxtal.operations import Orientation
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in range(10):
                v1 = random_vector()
                c1 = random_vector()
                o = Orientation.from_constraint(v1, c1)
        except Exception as e:
            fail(e)

    check()

    # =====symmetry=====
    print("pyxtal.symmetry")
    reset()
    try:
        import pyxtal.symmetry
    except Exception as e:
        fail(e)

    print("  get_wyckoffs (may take a moment)")
    try:
        from pyxtal.symmetry import get_wyckoffs
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in [1, 2, 229, 230]:
                get_wyckoffs(i)
                get_wyckoffs(i, organized=True)
        except:
            fail(" Could not access Wyckoff positions for space group # " +
                 str(i))

    check()

    print("  get_wyckoff_symmetry (may take a moment)")
    try:
        from pyxtal.symmetry import get_wyckoff_symmetry
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in [1, 2, 229, 230]:
                get_wyckoff_symmetry(i)
                get_wyckoff_symmetry(i, molecular=True)
        except:
            fail("Could not access Wyckoff symmetry for space group # " +
                 str(i))

    check()

    print("  get_wyckoffs_generators (may take a moment)")
    try:
        from pyxtal.symmetry import get_wyckoff_generators
    except Exception as e:
        fail(e)

    if passed():
        try:
            for i in [1, 2, 229, 230]:
                get_wyckoff_generators(i)
        except:
            fail("Could not access Wyckoff generators for space group # " +
                 str(i))

    check()

    print("  letter_from_index")
    try:
        from pyxtal.symmetry import letter_from_index
    except Exception as e:
        fail(e)

    if passed():
        try:
            if letter_from_index(0, get_wyckoffs(47)) == "A":
                pass
            else:
                fail()
        except Exception as e:
            fail(e)

    check()

    print("  index_from_letter")
    try:
        from pyxtal.symmetry import index_from_letter
    except Exception as e:
        fail(e)

    if passed():
        try:
            if index_from_letter("A", get_wyckoffs(47)) == 0:
                pass
            else:
                fail()
        except Exception as e:
            fail(e)

    check()

    print("  jk_from_i")
    try:
        from pyxtal.symmetry import jk_from_i
    except Exception as e:
        fail(e)

    if passed():
        try:
            w = get_wyckoffs(2, organized=True)
            j, k = jk_from_i(1, w)
            if j == 1 and k == 0:
                pass
            else:
                print(j, k)
                fail()
        except Exception as e:
            fail(e)

    check()

    print("  i_from_jk")
    try:
        from pyxtal.symmetry import i_from_jk
    except Exception as e:
        fail(e)

    if passed():
        try:
            w = get_wyckoffs(2, organized=True)
            j, k = jk_from_i(1, w)
            i = i_from_jk(j, k, w)
            if i == 1:
                pass
            else:
                print(j, k)
                fail()
        except Exception as e:
            fail(e)

    check()

    print("  ss_string_from_ops")
    try:
        from pyxtal.symmetry import ss_string_from_ops
    except Exception as e:
        fail(e)

    if passed():
        try:
            strings = ["1", "4 . .", "2 3 ."]
            for i, sg in enumerate([1, 75, 195]):
                ops = get_wyckoffs(sg)[0]
                ss_string_from_ops(ops, sg, dim=3)
        except Exception as e:
            fail(e)

    check()

    print("  Wyckoff_position")
    try:
        from pyxtal.symmetry import Wyckoff_position
    except Exception as e:
        fail(e)

    if passed():
        try:
            wp = Wyckoff_position.from_group_and_index(20, 1)
        except Exception as e:
            fail(e)

    check()

    print("  Group")
    try:
        from pyxtal.symmetry import Group
    except Exception as e:
        fail(e)

    if passed():
        try:
            g3 = Group(230)
            g2 = Group(80, dim=2)
            g1 = Group(75, dim=1)
        except Exception as e:
            fail(e)

    check()

    # =====crystal=====
    print("pyxtal.crystal")
    reset()
    try:
        import pyxtal.crystal
    except Exception as e:
        fail(e)

    print("  random_crystal")
    try:
        from pyxtal.crystal import random_crystal
    except Exception as e:
        fail(e)

    if passed():
        try:
            c = random_crystal(1, ["H"], [1], 10.0)
            if c.valid is True:
                pass
            else:
                fail()
        except Exception as e:
            fail(e)

    check()

    print("  random_crystal_2D")
    try:
        from pyxtal.crystal import random_crystal_2D
    except Exception as e:
        fail(e)

    if passed():
        try:
            c = random_crystal_2D(1, ["H"], [1], 10.0)
            if c.valid is True:
                pass
            else:
                fail()
        except Exception as e:
            fail(e)

    check()

    # =====molecule=====
    print("pyxtal.molecule")
    reset()
    try:
        import pyxtal.molecule
    except Exception as e:
        fail(e)

    check()

    print("  Collections")
    try:
        from pyxtal.molecule import mol_from_collection
    except Exception as e:
        fail(e)

    if passed():
        try:
            h2o = mol_from_collection("H2O")
            ch4 = mol_from_collection("CH4")
        except Exception as e:
            fail(e)

    print("  get_inertia_tensor")
    try:
        from pyxtal.molecule import get_inertia_tensor
    except Exception as e:
        fail(e)

    if passed():
        try:
            get_inertia_tensor(h2o)
            get_inertia_tensor(ch4)
        except Exception as e:
            fail(e)

    check()

    print("  get_moment_of_inertia")
    try:
        from pyxtal.molecule import get_moment_of_inertia
    except Exception as e:
        fail(e)

    if passed():
        try:
            v = random_vector()
            get_moment_of_inertia(h2o, v)
            get_moment_of_inertia(ch4, v)
        except Exception as e:
            fail(e)

    check()

    print("  reoriented_molecule")
    try:
        from pyxtal.molecule import reoriented_molecule
    except Exception as e:
        fail(e)

    if passed():
        try:
            reoriented_molecule(h2o)
            reoriented_molecule(ch4)
        except Exception as e:
            fail(e)

    check()

    print("  orientation_in_wyckoff_position")
    try:
        from pyxtal.molecule import orientation_in_wyckoff_position
    except Exception as e:
        fail(e)

    if passed():
        try:
            w = get_wyckoffs(20)
            ws = get_wyckoff_symmetry(20, molecular=True)
            wp = Wyckoff_position.from_group_and_index(20, 1)
            orientation_in_wyckoff_position(h2o, wp)
            orientation_in_wyckoff_position(ch4, wp)
        except Exception as e:
            fail(e)

    check()

    # =====molecular_crystal=====
    print("pyxtal.molecular_crystal")
    reset()
    try:
        import pyxtal.crystal
    except Exception as e:
        fail(e)

    print("  molecular_crystal")
    try:
        from pyxtal.molecular_crystal import molecular_crystal
    except Exception as e:
        fail(e)

    if passed():
        try:
            c = molecular_crystal(1, ["H2O"], [1], 10.0)
            if c.valid is True:
                pass
            else:
                fail()
        except Exception as e:
            fail(e)

    check()

    print("  molecular_crystal_2D")
    try:
        from pyxtal.molecular_crystal import molecular_crystal_2D
    except Exception as e:
        fail(e)

    if passed():
        try:
            c = molecular_crystal_2D(1, ["H2O"], [1], 10.0)
            if c.valid is True:
                pass
            else:
                fail()
        except Exception as e:
            fail(e)

    check()

    end(condition=2)
Exemple #5
0
    def from_random(
        self,
        dim=3,
        group=None,
        species=None,
        numIons=None,
        factor=1.1,
        thickness=None,
        area=None,
        lattice=None,
        sites=None,
        conventional=True,
        diag=False,
        t_factor=1.0,
        max_count=10,
        force_pass=False,
    ):
        if self.molecular:
            prototype = "molecular"
        else:
            prototype = "atomic"
        tm = Tol_matrix(prototype=prototype, factor=t_factor)

        count = 0
        quit = False

        while True:
            count += 1
            if self.molecular:
                if dim == 3:
                    struc = molecular_crystal(group,
                                              species,
                                              numIons,
                                              factor,
                                              lattice=lattice,
                                              sites=sites,
                                              conventional=conventional,
                                              diag=diag,
                                              tm=tm)
                elif dim == 2:
                    struc = molecular_crystal_2D(group,
                                                 species,
                                                 numIons,
                                                 factor,
                                                 thickness=thickness,
                                                 sites=sites,
                                                 conventional=conventional,
                                                 tm=tm)
                elif dim == 1:
                    struc = molecular_crystal_1D(group,
                                                 species,
                                                 numIons,
                                                 factor,
                                                 area=area,
                                                 sites=sites,
                                                 conventional=conventional,
                                                 tm=tm)
            else:
                if dim == 3:
                    struc = random_crystal(group, species, numIons, factor,
                                           lattice, sites, conventional, tm)
                elif dim == 2:
                    struc = random_crystal_2D(group, species, numIons, factor,
                                              thickness, lattice, sites,
                                              conventional, tm)
                elif dim == 1:
                    struc = random_crystal_1D(group, species, numIons, factor,
                                              area, lattice, sites,
                                              conventional, tm)
                else:
                    struc = random_cluster(group, species, numIons, factor,
                                           lattice, sites, tm)
            if force_pass:
                quit = True
                break
            elif struc.valid:
                quit = True
                break

            if count >= max_count:
                raise RuntimeError(
                    "It takes long time to generate the structure, check inputs"
                )

        if quit:
            self.valid = struc.valid
            self.dim = dim
            try:
                self.lattice = struc.lattice
                if self.molecular:
                    self.numMols = struc.numMols
                    self.molecules = struc.molecules
                    self.mol_sites = struc.mol_sites
                    self.diag = struc.diag
                else:
                    self.numIons = struc.numIons
                    self.species = struc.species
                    self.atom_sites = struc.atom_sites
                self.group = struc.group
                self.PBC = struc.PBC
                self.source = 'random'
                self.factor = struc.factor
                self.number = struc.number
                self._get_formula()
            except:
                pass
Exemple #6
0
def test_atomic_2D():
    global outstructs
    global outstrings
    print("=== Testing generation of atomic 2D crystals. This may take some time. ===")
    from time import time
    from spglib import get_symmetry_dataset
    from pyxtal.symmetry import get_layer
    from pyxtal.crystal import random_crystal_2D
    from pyxtal.crystal import cellsize
    from pyxtal.database.layergroup import Layergroup
    from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
    slow = []
    failed = []
    print("   Layergroup   | sg # Expected |Generated (SPG)|Generated (PMG)|Time Elapsed")
    skip = []#slow to generate
    for num in range(1, 81):
        if num not in skip:
            sg = Layergroup(num).sgnumber
            multiplicity = len(get_layer(num)[0]) / cellsize(sg) #multiplicity of the general position
            start = time()
            rand_crystal = random_crystal_2D(num, ['H'], [multiplicity], 4.0)
            end = time()
            timespent = np.around((end - start), decimals=2)
            t = str(timespent)
            if len(t) == 3:
                t += "0"
            t += " s"
            if timespent >= 1.0:
                t += " ~"
            if timespent >= 3.0:
                t += "~"
            if timespent >= 10.0:
                t += "~"
            if timespent >= 60.0:
                t += "~"
                slow.append(num)
            if rand_crystal.valid:
                check = False
                ans1 = get_symmetry_dataset(rand_crystal.spg_struct, symprec=1e-1)
                if ans1 is None:
                    ans1 = "???"
                else:
                    ans1 = ans1['number']
                sga = SpacegroupAnalyzer(rand_crystal.struct)
                ans2 = "???"
                if sga is not None:
                    try:
                        ans2 = sga.get_space_group_number()
                    except: ans2 = "???"
                if ans2 is None:
                    ans2 = "???"

                #Compare expected and detected groups
                if ans1 == "???" and ans2 == "???":
                    check = True
                elif ans1 == "???":
                    if int(ans2) > sg: pass
                elif ans2 == "???":
                    if int(ans1) > sg: pass
                else:
                    if ans1 < sg and ans2 < sg:
                        if compare_wyckoffs(sg, ans1) or compare_wyckoffs(sg, ans2): pass
                        else: check = True

                #output cif files for incorrect space groups
                if check is True:
                    if check_struct_group(rand_crystal.struct, num, dim=2):
                        pass
                    else:
                        t += " xxxxx"
                        outstructs.append(rand_crystal.struct)
                        outstrings.append(str("2D_Atomic_"+str(num)+".vasp"))
                print("\t"+str(num)+"\t|\t"+str(sg)+"\t|\t"+str(ans1)+"\t|\t"+str(ans2)+"\t|\t"+t)
            else:
                print("~~~~ Error: Could not generate layer group "+str(num)+" after "+t)
                failed.append(num)
    if slow != []:
        print("~~~~ The following layer groups took more than 60 seconds to generate:")
        for i in slow:
            print("     "+str(i))
    if failed != []:
        print("~~~~ The following layer groups failed to generate:")
        for i in failed:
            print("     "+str(i))
parameters = ["mass * 1.",
              "pair_style tersoff",
              "pair_coeff * * SiCGe.tersoff C",
             ]

strain = np.zeros([3,3]) 
strain[:2,:2] += 1
# Here we do plane groups
pgs = [3, 11, 12, 13, 23, 24, 25, 26, 49, 55, 56, 65, 69, 70, 73, 75]

filename = '06.db'
with connect(filename) as db:
    for i in range(100):
        while True:
            sg, numIons = choice(pgs), choice(range(4,24))
            struc = random_crystal_2D(sg, ["C"], [numIons], thickness=0)
            if struc.valid:
                ase_struc = struc.to_ase()
                break
        s, eng = lmp_run(ase_struc, lmp, parameters, method='opt', path=calc_folder)
        # relax the structure with multiple steps
        for m in range(2):
            s = lmp_opt(s, lmp, parameters, strain=strain, fmax=0.01, path=calc_folder)
            s, eng = lmp_run(s, lmp, parameters, method='opt', path=calc_folder)

        s, eng, _, error = gulp_opt(s, ff='tersoff.lib', path=calc_folder, symmetrize=False)
        if error:
            spg = get_symmetry_dataset(s, symprec=1e-1)['international']
            pos = s.get_positions()[:,2]
            thickness = max(pos) - min(pos) 
            new = new_struc(db, s, eng)
Exemple #8
0
import pyxtal
print("PyXtal: ", pyxtal.__version__)

import ase
print("ase: ", ase.__version__)

from pyxtal.crystal import random_crystal_2D
print("Using PyXtal to generate structure")
struc = random_crystal_2D(75, ["C"], [4], thickness=0)
print("Convert PyXtal structure to ASE")
ase_struc = struc.to_ase()

from pyxtal.interface.lammpslib import run_lammpslib
from pyxtal.interface.gulp import single_optimize as gulp_opt
from lammps import lammps

# Set up lammps
import os
calc_folder = 'tmp'
for folder in [calc_folder]:
    if not os.path.exists(folder):
        os.makedirs(folder)

lammps_name = ''
comm = None
log_file = calc_folder + '/lammps.log'
cmd_args = ['-echo', 'log', '-log', log_file, '-screen', 'none', '-nocite']
lmp = lammps(lammps_name, cmd_args, comm)
parameters = [
    "mass * 1.",
    "pair_style tersoff",
Exemple #9
0
 def test_mutiple_species(self):
     struc = random_crystal_2D(4, ["Mo", "S"], [2, 4], 1.0)
     self.assertTrue(struc.valid)
Exemple #10
0
 def test_single_specie(self):
     struc = random_crystal_2D(20, ["C"], [4], 1.0, thickness=2.0)
     struc.to_file()
     self.assertTrue(struc.valid)
Exemple #11
0
    #verbosity = options.verbosity
    attempts = options.attempts
    outdir = options.outdir
    dimension = options.dimension
    thickness = options.thickness

    if not os.path.exists(outdir):
        os.mkdir(outdir)

    for i in range(attempts):
        numIons0 = np.array(numIons)
        start = time()
        if dimension == 3:
            rand_crystal = random_crystal(sg, system, numIons0, factor)
        elif dimension == 2:
            rand_crystal = random_crystal_2D(sg, system, numIons0, factor, thickness)
        elif dimension == 1:                                             
            rand_crystal = random_crystal_1D(sg, system, numIons0, factor, thickness)
        if dimension == 0:
            rand_crystal = random_cluster(sg, system, numIons0, factor)
        end = time()
        timespent = np.around((end - start), decimals=2)

        if rand_crystal.valid:
            # Output a cif or xyz file
            pmg_struc = rand_crystal.to_pymatgen()
            ase_struc = rand_crystal.to_ase()
            comp = str(pmg_struc.composition)
            comp = comp.replace(" ", "")
            if dimension > 0:
                outpath = outdir + "/" + comp + ".cif"