Beispiel #1
0
    def test_sites(self):
        struc = molecular_crystal(36, ["H2O"], [2])
        pmg_struc = struc.to_pymatgen()
        sga = SpacegroupAnalyzer(pmg_struc)
        self.assertTrue(sga.get_space_group_symbol() == "Cmc2_1")

        struc = molecular_crystal(36, ["H2O"], [4], sites=[["4a", "4a"]])
        pmg_struc = struc.to_pymatgen()
        sga = SpacegroupAnalyzer(pmg_struc)
        self.assertTrue(sga.get_space_group_symbol() == "Cmc2_1")
Beispiel #2
0
 def test_big_molecule(self):
     # print("test_big_molecule")
     for mol in ["ROY", "aspirin"]:
         struc = molecular_crystal(19, ["ROY"], [4], 1.2)
         self.assertTrue(struc.valid)
         pair = struc.check_short_distances()
         if len(pair) > 0:
             print("short distances were detected")
             print(mol)
             print(pair)
         self.assertTrue(len(pair) == 0)
Beispiel #3
0
    def test_mutiple_species(self):
        Li = Molecule(["Li"], [[0.0, 0.0, 0.0]])
        coords = [
            [0.000000, 0.000000, 0.000000],
            [1.200000, 1.200000, -1.200000],
            [1.200000, -1.200000, 1.200000],
            [-1.200000, 1.200000, 1.200000],
            [-1.200000, -1.200000, -1.200000],
        ]
        ps4 = Molecule(["P", "S", "S", "S", "S"], coords)

        for i in range(3):
            struc = molecular_crystal(10, [Li, ps4], [6, 2], 1.2)
            if struc.valid:
                self.assertTrue(len(struc.to_pymatgen()) == 16)
Beispiel #4
0
    def test_single_specie(self):
        # print("test_h2o")
        struc = molecular_crystal(36, ["H2O"], [4], sites=[["8b"]])
        struc.to_file()
        self.assertTrue(struc.valid)

        # test space group
        pmg_struc = struc.to_pymatgen()
        sga = SpacegroupAnalyzer(pmg_struc)
        # print(sga.get_space_group_symbol())
        self.assertTrue(sga.get_space_group_number() >= 36)
        # print(pmg_struc.frac_coords[:3])

        # test rotation
        ax = struc.mol_sites[0].orientation.axis
        struc.mol_sites[0].rotate(axis=[1, 0, 0], angle=90)
        pmg_struc = struc.to_pymatgen()
        sga = SpacegroupAnalyzer(pmg_struc)
        pmg_struc.to("cif", "1.cif")
        self.assertTrue(sga.get_space_group_symbol() == "Cmc2_1")
Beispiel #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
        os.makedirs(folder)

#para = Lattice.from_para(4.45, 7.70, 7.28, 90, 90, 90)

# Here we generate many random structures and optimize them
data = {  #"ID":[],
    "Sym": [],
    "Eng": [],
    "abc": [],
    "Volume": [],
}

for i in range(1):
    while True:
        sg = randint(2, 230)
        crystal = molecular_crystal(sg, ['H2O'], [randint(1, 4)],
                                    1.0)  #, lattice=para)
        if crystal.valid:
            struc = Atoms(
                crystal.spg_struct[2],
                cell=crystal.spg_struct[0],
                scaled_positions=crystal.spg_struct[1],
            )
            break
    #struc = struc.repeat((2,2,2))
    lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, mol=True)
    struc.set_calculator(lammps)
    box = mushybox(struc)

    dyn = FIRE(box)
    dyn.run(fmax=0.00, steps=1100)
        os.makedirs(folder)

#para = Lattice.from_para(4.45, 7.70, 7.28, 90, 90, 90)

# Here we generate many random structures and optimize them
data = {  #"ID":[],
    "Sym": [],
    "Eng": [],
    "abc": [],
    "Volume": [],
}

for i in range(100):
    while True:
        sg = randint(16, 191)
        crystal = molecular_crystal(sg, ['H2O'], [4], 1.0)  #, lattice=para)
        if crystal.valid:
            struc = Atoms(
                crystal.spg_struct[2],
                cell=crystal.spg_struct[0],
                scaled_positions=crystal.spg_struct[1],
            )
            break
    #struc = struc.repeat((2,2,2))
    lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, mol=True)
    struc.set_calculator(lammps)
    box = mushybox(struc)
    dyn = FIRE(box)
    dyn.run(fmax=0.01, steps=200)
    dyn = BFGS(box)
    dyn.run(fmax=0.01, steps=200)
from random import randint
from time import time
from pymatgen.io.cif import CifWriter
import os

mols = [
    'CH4', 'H2O', 'NH3', 'urea', 'benzene', 'roy', 'aspirin', 'pentacene',
    'C60'
]
filename = 'out.cif'
if os.path.isfile(filename):
    os.remove(filename)

for mol in mols:
    for i in range(10):
        run = True
        while run:
            sg = randint(4, 191)
            start = time()
            rand_crystal = molecular_crystal(sg, [mol], [4], 1.0)
            if rand_crystal.valid:
                run = False
                print(
                    'Mol:{0:10s}  SG:{1:3d} Time:{2:4.2f} seconds, N_attempts:{3:4d} Vol: {4:6.2f}'
                    .format(mol, sg,
                            time() - start, rand_crystal.numattempts,
                            rand_crystal.volume))
                content = str(CifWriter(rand_crystal.struct, symprec=0.1))
                with open(filename, 'a+') as f:
                    f.writelines(content)
     "atom_style full",
     "pair_style      lj/cut/tip4p/long 1 2 1 1 0.278072379 17.007",
     "bond_style      class2 ",
     "angle_style     harmonic",
     "kspace_style pppm/tip4p 0.0001",
     "read_data tmp/data.lammps",
     "pair_coeff  * * 0 0",
     "pair_coeff  1  1  0.000295147 5.96946",
     "neighbor 2.0 bin",
     "min_style cg",
     "minimize 1e-6 1e-6 10000 10000",
 ]
 para = Lattice.from_para(4.45, 7.70, 7.28, 90, 90, 90)
 strucs = []
 for i in range(10):
     crystal = molecular_crystal(36, ['H2O'], [2], 1.0, lattice=para)
     struc = Atoms(
         crystal.spg_struct[2],
         cell=crystal.spg_struct[0],
         scaled_positions=crystal.spg_struct[1],
     )
     struc.write('0.vasp', format='vasp', vasp5=True)
     #struc = optimize_lammpslib(pbcgb, lmp, method='FIRE', fmax=0.1, path=tmp)
     #struc = struc.repeat((2,2,2))
     lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, mol=True)
     struc.set_calculator(lammps)
     box = mushybox(struc)
     dyn = FIRE(box)
     dyn.run(fmax=0.01, steps=500)
     dyn = BFGS(box)
     dyn.run(fmax=0.01, steps=500)
Beispiel #10
0
        coords = []
        for ms in mol_sites:
            coords1, species1 = ms.get_coords_and_species()
            species += species1
            for c in coords1:
                coords.append(c)
        coords = np.array(coords)
        Structure.__init__(self, lattice.matrix, species, coords)

    @classmethod
    def from_molecular_crystal(self, mc):
        """
        Initialize from a molecular_crystal object
        """
        if mc.valid:
            return Mstruct(mc.mol_generators, mc.lattice, mc.group)
        else:
            return None


if __name__ == "__main__":
    from pyxtal.crystal import random_crystal
    c = random_crystal(225, ['C'], [4], 1)
    x = Xstruct.from_random_crystal(c)
    print(x.group)

    from pyxtal.molecular_crystal import molecular_crystal
    m = molecular_crystal(20, ['H2O'], [8], 1)
    x = Mstruct.from_molecular_crystal(m)
    print(x.group)
Beispiel #11
0
            numMols.append(int(x))
    else:
        system = [molecule]
        numMols = [int(number)]

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

    for i in range(attempts):
        start = time()
        numMols0 = np.array(numMols)
        if dimension == 3:
            print(sg, system, numMols0, factor)
            rand_crystal = molecular_crystal(
                sg,
                system,
                numMols0,
                factor,
            )
        elif dimension == 2:
            rand_crystal = molecular_crystal_2D(
                sg,
                system,
                numMols0,
                factor,
                thickness,
            )
        end = time()
        timespent = np.around((end - start), decimals=2)
        if rand_crystal.valid:
            pmg_struc = rand_crystal.to_pymatgen()
            ase_struc = rand_crystal.to_ase()
Beispiel #12
0
 def test_read(self):
     # test reading structure from external
     struc = molecular_crystal(14, ["aspirin"], [4], seed=cif_path)
     pmg_struc = struc.to_pymatgen()
     sga = SpacegroupAnalyzer(pmg_struc)
     self.assertTrue(sga.get_space_group_symbol() == "P2_1/c")
Beispiel #13
0
 def test_preassigned_sites(self):
     sites = [["4a", "4a"]]
     struc = molecular_crystal(36, ["H2O"], [4], sites=sites)
     self.assertTrue(struc.valid)
Beispiel #14
0
def test_molecular():
    global outstructs
    global outstrings
    print(
        "=== Testing generation of molecular 3D crystals. This may take some time. ==="
    )
    from time import time
    from spglib import get_symmetry_dataset
    from pyxtal.symmetry import get_wyckoffs
    from pyxtal.crystal import cellsize
    from pyxtal.molecular_crystal import molecular_crystal
    from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

    slow = []
    failed = []
    print("  Spacegroup #  |Generated (SPG)|Generated (PMG)|  Time Elapsed")
    skip = (
        []
    )  # [24, 183, 202, 203, 209, 210, 216, 219, 225, 226, 227, 228, 229, 230] #slow
    for sg in range(1, 231):
        if sg not in skip:
            multiplicity = len(get_wyckoffs(sg)[0]) / cellsize(
                sg)  # multiplicity of the general position
            start = time()
            rand_crystal = molecular_crystal(sg, ["H2O"], [multiplicity], 2.5)
            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:
                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, sg, dim=3):
                        pass
                    else:
                        t += " xxxxx"
                        outstructs.append(rand_crystal.struct)
                        outstrings.append(
                            str("3D_Molecular_" + str(sg) + ".vasp"))
                print("\t" + str(sg) + "\t|\t" + str(ans1) + "\t|\t" +
                      str(ans2) + "\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))
    "pair_style      lj/cut/tip4p/long 1 2 1 1 0.278072379 17.007",
    "bond_style      class2 ",
    "angle_style     harmonic",
    "kspace_style pppm/tip4p 0.0001",
    "read_data 07-tmp/data.lammps",
    "pair_coeff  2  2 0 0",
    "pair_coeff  1  2 0 0",
    "pair_coeff  1  1  0.000295147 5.96946",
]

filename = '07.db'
with connect(filename) as db:
    for i in range(100):
        while True:
            sg, numIons = choice(range(3, 231)), choice(range(4, 6))
            struc = molecular_crystal(19, ["H2O"], [8])
            if struc.valid:
                break
        s = struc.to_ase(resort=False)
        s, _ = lmp_run(s,
                       lmp,
                       parameters,
                       molecule=True,
                       method='opt',
                       path=calc_folder)
        s = lmp_opt(s,
                    lmp,
                    parameters,
                    molecule=True,
                    fmax=0.01,
                    path=calc_folder)
Beispiel #16
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)
Beispiel #17
0
 def test_c60(self):
     struc = molecular_crystal(36, ["C60"], [2], 1.0)
     self.assertTrue(struc.valid)