예제 #1
0
파일: test_all.py 프로젝트: gipfeli/PyXtal
    def test_multi_sites(self):
        struc = random_cluster(1, ["C"], [60], 1.0)
        struc.to_file()
        self.assertTrue(struc.valid)

        struc = random_cluster(3, ["C"], [60], 1.0)
        struc.to_file()
        self.assertTrue(struc.valid)
예제 #2
0
def test_cluster():
    global outstructs
    global outstrings
    print(
        "=== Testing generation of point group clusters. This may take some time. ==="
    )
    from time import time
    from spglib import get_symmetry_dataset
    from pyxtal.symmetry import Group
    from pyxtal.crystal import random_cluster
    from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

    slow = []
    failed = []
    print("  Point group # |     Symbol    |  Time Elapsed")
    skip = []  # [32,55,56]#[28,29,30,31,32,55,56]
    for sg in range(1, 57):
        if sg not in skip:
            multiplicity = len(Group(
                sg, dim=0)[0])  # multiplicity of the general position
            start = time()
            rand_crystal = random_cluster(sg, ["C"], [multiplicity], 1.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=0):
                    pass
                else:
                    t += " xxxxx"
                    outstructs.append(rand_crystal.struct)
                    outstrings.append(str("Cluster_" + str(sg) + ".vasp"))
                pgsymbol = Group(sg, dim=0).symbol
                print("\t" + str(sg) + "\t|\t" + pgsymbol + "\t|\t" + t)
            else:
                print("~~~~ Error: Could not generate space group " + str(sg) +
                      " after " + t)
                failed.append(sg)
    if slow != []:
        print(
            "~~~~ The following space groups took more than 60 seconds to generate:"
        )
        for i in slow:
            print("     " + str(i))
    if failed != []:
        print("~~~~ The following space groups failed to generate:")
        for i in failed:
            print("     " + str(i))
예제 #3
0
파일: LJ_38_Oh.py 프로젝트: yfyh2013/PyXtal
 def generate_cluster(self, pgs=range(2, 33)):
     run = True
     while run:
         pg = choice(pgs)
         cluster = random_cluster(pg, ['Mo'], [self.numIons], 1.0)
         if cluster.valid:
             run = False
     return cluster.cart_coords
예제 #4
0
 def generate_cluster(self, pgs=range(2, 33)):
     run = True
     while run:
         pg = choice(pgs)
         cluster = random_cluster(
             pg,
             ["Mo"],
             [self.numIons],
             volume_factor,
             tm=Tol_matrix(prototype="atomic", factor=cluster_factor),
         )
         if cluster.valid:
             run = False
     return cluster.to_pymatgen().cart_coords
예제 #5
0
 def generate_cluster(self, pgs=range(2, 33)):
     run = True
     while run:
         pg = choice(pgs)
         cluster = random_cluster(pg, ['Mo'], [self.numIons],
                                  volume_factor,
                                  tm=Tol_matrix(prototype="atomic",
                                                factor=cluster_factor))
         if cluster.valid:
             run = False
     try:
         return cluster.cart_coords
     except:
         return cluster.coordinates
예제 #6
0
def gen_cluster(system, numIons, sg=None, dimension=0, factor=1.0):
    #space group
    if sg:
        pass
    else:
        sg = random.choice(range(1, 57))
    symbol, sg = get_symbol_and_number(sg, dimension)

    numIons0 = np.array(numIons)
    cluster = random_cluster(sg, system, numIons0, factor)
    if cluster.valid:
        comp = str(cluster.struct.composition)
        comp = comp.replace(" ", "")
        #outpath ='./' + comp + '.xyz'
        #print('out file name %s'%outpath)
        #cluster.molecule.to('xyz,', outpath)
        #cluster.to_file(filename = outpath, fmt='xyz')
        #mol=Molecule.from_file(outpath)
        mol = cluster.molecule

        xmax = mol.cart_coords[:, 0].max()
        xmin = mol.cart_coords[:, 0].min()
        ymax = mol.cart_coords[:, 1].max()
        ymin = mol.cart_coords[:, 1].min()
        zmax = mol.cart_coords[:, 2].max()
        zmin = mol.cart_coords[:, 2].min()
        lx = xmax - xmin
        ly = ymax - ymin
        lz = zmax - zmin
        _a, _b, _c = sorted([lx, ly, lz])
        if _b / _a > 2 or _c / _b > 2 or _c / _a > 2:
            print("too long")
            return None

        ans = PointGroupAnalyzer(mol).sch_symbol
        print('Symmetry requested: {:d}({:s}), generated: {:s}'.format(
            sg, symbol, ans))
        #a=b=c=np.max(mol.distance_matrix)+10
        a = lx + 10
        b = ly + 10
        c = lz + 10
        st = mol.get_boxed_structure(a, b, c)
        #st.to('POSCAR','rand_'+comp+'.vasp')
        #print(st)
        print('valid')
        return st
    else:
        print('cannot generate corresponding structure, retry it!')
        return None
예제 #7
0
파일: randoms.py 프로젝트: wwmeng/maptool
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
예제 #8
0
def gen_cluster(system,numIons,sg=None,dimension=0,factor=1.0):
    #space group
    random.seed(int(time.time()*1e5))
    if sg:
       pass
    else:
       sg=random.choice(range(1,57))
    symbol, sg = get_symbol_and_number(sg, dimension)

    numIons0 = np.array(numIons)
    cluster = random_cluster(sg, system, numIons0, factor)
    if cluster.valid:
       comp = str(cluster.struct.composition)
       comp = comp.replace(" ", "")
       #outpath ='./' + comp + '.xyz'
       #print('out file name %s'%outpath)
       #cluster.molecule.to('xyz,', outpath)
       #cluster.to_file(filename = outpath, fmt='xyz')
       #mol=Molecule.from_file(outpath)
       mol=cluster.molecule
       ans = PointGroupAnalyzer(mol).sch_symbol
       print('Symmetry requested: {:d}({:s}), generated: {:s}'.format(sg, symbol, ans))
       a=max(mol.cart_coords[:,0])-min(mol.cart_coords[:,0])
       b=max(mol.cart_coords[:,1])-min(mol.cart_coords[:,1])
       c=max(mol.cart_coords[:,2])-min(mol.cart_coords[:,2])
       lx,ly,lz=sorted([a,b,c])
       if lz/ly>2 or ly/lx>2 or lz/lx>2:
          print('too long')
          return None
       st=mol.get_boxed_structure(a+vac,b+vac,c+vac)
       #st.to('POSCAR','rand_'+comp+'.vasp')
       #print(st)
       print('valid')
       return st
    else:
       print('cannot generate corresponding structure, retry it!')
       return None
예제 #9
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
예제 #10
0
파일: test_all.py 프로젝트: gipfeli/PyXtal
 def test_mutiple_species(self):
     struc = random_cluster(4, ["Mo", "S"], [2, 4], 1.0)
     self.assertTrue(struc.valid)
예제 #11
0
파일: test_all.py 프로젝트: gipfeli/PyXtal
 def test_single_specie(self):
     struc = random_cluster("Ih", ["C"], [60], 1.0)
     struc.to_file()
     self.assertTrue(struc.valid)
예제 #12
0
    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"
                CifWriter(pmg_struc, symprec=0.1).write_file(filename=outpath)
            else:
                outpath = outdir + "/" + comp + ".xyz"
                rand_crystal.to_file(filename=outpath, fmt="xyz")