Пример #1
0
def test_system_read():
    sys = pc.System()
    sys.read_inputfile('tests/conf.dump')
    atoms = sys.atoms
    assert len(atoms) == 500

    #check box
    assert sys.box == [[18.85618, 0.0, 0.0], [0.0, 18.86225, 0.0],
                       [0.0, 0.0, 19.01117]]
    #check few atoms
    filtered_atoms = [atom for atom in atoms if atom.id == 204]
    assert filtered_atoms[0].pos == [-0.10301, -6.35752, -6.44787]

    #now check the same for zipped file
    sys = pc.System()
    sys.read_inputfile('tests/conf.dump.gz')
    atoms = sys.atoms
    assert len(atoms) == 500

    #check box
    assert sys.box == [[18.85618, 0.0, 0.0], [0.0, 18.86225, 0.0],
                       [0.0, 0.0, 19.01117]]

    #check few atoms
    filtered_atoms = [atom for atom in atoms if atom.id == 204]
    assert filtered_atoms[0].pos == [-0.10301, -6.35752, -6.44787]
    #del sys

    sys = pc.System()
    with pytest.raises(IOError):
        sys.read_inputfile('tests/ahdkklc.dump')
Пример #2
0
def test_create_multislice_dump():
    """
    Create a multitest dump file and test it
    """
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[6, 6, 6])
    sys = pc.System()
    sys.box = boxdims
    sys.atoms = atoms

    ptp.write_file(sys, "tests/bcc1.dump")

    atoms2, boxdims2 = pcs.make_crystal('bcc', repetitions=[6, 6, 6])
    #modify the coordinates of one atom
    x = atoms2[0].pos
    x[0] += 0.01
    atoms2[0].pos = x
    assert len(atoms2) == 432
    #write it out
    sys2 = pc.System()
    sys2.box = boxdims2
    sys2.atoms = atoms2

    ptp.write_file(sys2, "tests/bcc2.dump")

    #now cleanup
    if os.path.exists("tests/bcc1.dat"):
        os.remove("tests/bcc1.dat")
    if os.path.exists("tests/bcc2.dat"):
        os.remove("tests/bcc2.dat")
Пример #3
0
def test_lammps_dump():
    sys = pc.System()
    sys.read_inputfile('tests/conf.dump')
    atoms = sys.atoms
    assert len(atoms) == 500

    #check box
    assert sys.box == [[-7.66608, 11.1901], [-7.66915, 11.1931],
                       [-7.74357, 11.2676]]

    #check few atoms
    filtered_atoms = [atom for atom in atoms if atom.id == 204]
    assert filtered_atoms[0].pos == [-0.10301, -6.35752, -6.44787]

    #now check the same for zipped file
    sys = pc.System()
    sys.read_inputfile('tests/conf.dump.gz')
    atoms = sys.atoms
    assert len(atoms) == 500

    #check box
    assert sys.box == [[-7.66608, 11.1901], [-7.66915, 11.1931],
                       [-7.74357, 11.2676]]

    #check few atoms
    filtered_atoms = [atom for atom in atoms if atom.id == 204]
    assert filtered_atoms[0].pos == [-0.10301, -6.35752, -6.44787]
Пример #4
0
def test_cna_adaptive():
    atoms, box = pcs.make_crystal(structure="fcc",
                                  repetitions=(7, 7, 7),
                                  lattice_constant=4.00,
                                  noise=0.1)
    sys = pc.System()
    sys.atoms = atoms
    sys.box = box
    sys.calculate_cna(cutoff=None)
    atoms = sys.atoms
    assert atoms[0].structure == 1

    atoms, box = pcs.make_crystal(structure="hcp",
                                  repetitions=(7, 7, 7),
                                  lattice_constant=4.00,
                                  noise=0.1)
    sys = pc.System()
    sys.atoms = atoms
    sys.box = box
    sys.calculate_cna(cutoff=None)
    atoms = sys.atoms
    assert atoms[0].structure == 2

    atoms, box = pcs.make_crystal(structure="bcc",
                                  repetitions=(7, 7, 7),
                                  lattice_constant=4.00,
                                  noise=0.1)
    sys = pc.System()
    sys.atoms = atoms
    sys.box = box
    sys.calculate_cna(cutoff=None)
    atoms = sys.atoms
    assert atoms[0].structure == 3
Пример #5
0
def test_file_system():

    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [1, 1, 1])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims
    sys.find_neighbors(method = 'voronoi')

    sys.to_file('tests/tjkf.dat')

    #now try to read in the file
    sys2 = pc.System()
    sys2.read_inputfile('tests/tjkf.dat')
    assert len(sys2.atoms) == 2

    #now add some custom values
    atoms[0].custom = {"velocity":12}
    atoms[1].custom = {"velocity":24}

    #now try to read in the file
    sys3 = pc.System()
    sys3.atoms = atoms
    sys3.box = boxdims
    sys3.to_file('tests/tjkf.dat', custom=['velocity'])

    #now read it again
    sys4 = pc.System()
    sys4.read_inputfile('tests/tjkf.dat', customkeys=['velocity'])
    #now get atoms and check them
    atoms = sys4.atoms
    assert int(atoms[0].custom['velocity']) == 12
    assert int(atoms[1].custom['velocity']) == 24
def return_possible_polys(struct):
    if struct=='bcc':
        atoms, box = pcs.make_crystal('bcc', lattice_constant=4, repetitions=[3,3,3])
        sys = pc.System()
        sys.atoms = atoms
        sys.box = box
        sys.find_neighbors(method='voronoi')
        sys.calculate_vorovector()
        voros = [" ".join(np.array(atom.vorovector).astype(str)) for atom in sys.atoms]
        #take unique
        unique_voros = np.unique(voros)
    elif struct=='fcc':
        atoms, box = pcs.make_crystal('fcc', lattice_constant=4, repetitions=[3,3,3])
        sys = pc.System()
        sys.atoms = atoms
        sys.box = box
        sys.find_neighbors(method='voronoi')
        sys.calculate_vorovector()
        voros = [" ".join(np.array(atom.vorovector).astype(str)) for atom in sys.atoms]
        #take unique
        unique_voros = np.unique(voros)
    elif struct=='liquid':
        sys = pc.System()
        sys.read_inputfile('datafiles/lqd.dat')
        sys.find_neighbors(method='voronoi')
        sys.calculate_vorovector()
        voros = [" ".join(np.array(atom.vorovector).astype(str)) for atom in sys.atoms]
        #take unique
        unique_voros = np.unique(voros)
    elif struct=='distorted-bcc':
        sys = pc.System()
        sys.read_inputfile('datafiles/mixed_bcc.dat')
        sys.find_neighbors(method='voronoi')
        sys.calculate_vorovector(edge_cutoff=0.0, area_cutoff=0.0)
        voros = [" ".join(np.array(atom.vorovector).astype(str)) for atom in sys.atoms if atom.vorovector[1] >= 2]
        #take unique
        unique_voros = np.unique(voros)

    elif struct=='distorted-fcc':
        sys = pc.System()
        sys.read_inputfile('datafiles/mixed_fcc.dat')
        sys.find_neighbors(method='voronoi')
        sys.calculate_vorovector()
        voros = [" ".join(np.array(atom.vorovector).astype(str)) for atom in sys.atoms]
        #take unique
        unique_voros = np.unique(voros)

    #now create a dropdown widget with this option
    poly_widget = widgets.Dropdown(
        options=unique_voros,
        value=unique_voros[0],
        description='polyhedra:',
        disabled=False,
    )
    return widgets.interact(visualise_poly, poly=poly_widget, atoms=widgets.fixed(sys.atoms))
Пример #7
0
def test_q_4():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [4, 4, 4])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims
    #sys.get_neighbors(method = 'voronoi')
    sys.find_neighbors(method = 'cutoff', cutoff=0.9)
    sys.calculate_q([4, 6], averaged=True)
    atoms = sys.atoms
    #assert np.round(atoms[0].q[2], decimals=2) == 0.51
    assert np.round(atoms[0].get_q(4, averaged=True), decimals=2) == 0.51
    assert np.round(atoms[0].get_q([4, 6])[0], decimals=2) == 0.51
    assert np.round(atoms[0].get_q([4, 6], averaged=True)[1], decimals=2) == 0.63
    assert np.round(atoms[0].get_q([4, 6]), decimals=2)[0] == 0.51
    assert np.round(atoms[0].get_q([4, 6], averaged=True)[1], decimals=2) == 0.63

    #now change the q4 values
    atoms[0].set_q(4, .23)
    atoms[0].set_q(4, .23, averaged=True)
    assert np.round(atoms[0].get_q(4), decimals=2) == 0.23
    assert np.round(atoms[0].get_q(4, averaged=True), decimals=2) == 0.23

    atoms[0].set_q([4, 6], [.23, .46])
    atoms[0].set_q([4, 6], [.23, .46], averaged=True)
    assert np.round(atoms[0].get_q(4), decimals=2) == 0.23
    assert np.round(atoms[0].get_q(4, averaged=True), decimals=2) == 0.23
    assert np.round(atoms[0].get_q(6), decimals=2) == 0.46
    assert np.round(atoms[0].get_q(6, averaged=True), decimals=2) == 0.46
Пример #8
0
 def test_simple_system(self):
     """
     Test a simple ase to pyscal conversion
     """
     sysp = pc.System()
     sysp.read_inputfile(self.structure, format="ase")
     self.assertEqual(len(sysp.atoms), 256)
Пример #9
0
def test_cluster_cutoff():
    sys = pc.System()
    sys.read_inputfile('examples/cluster.dump')
    sys.find_neighbors(method='cutoff', cutoff=3.63)
    sys.find_solids(cluster=False)
    val = sys.cluster_atoms("solid", largest = True, cutoff=3.63)
    assert 176 == val
Пример #10
0
def test_others():
    sys = pc.System()
    sys.read_inputfile('tests/bcc.prim.dat')
    sys.to_file('tests/prim1', format="poscar", species=['Fe'])

    #try reading in
    sys = pc.System()
    sys.read_inputfile('tests/prim1', format="poscar")
    #aseobj = ptp.con
    ase = bulk('Cu', 'fcc', a=3.6).repeat((3, 3, 3))
    sys = pc.System()
    sys.read_inputfile(ase, format="ase")

    ase = bulk('Cu', 'fcc', a=3.6, cubic=True).repeat((3, 3, 3))
    sys = pc.System()
    sys.read_inputfile(ase, format="ase")
Пример #11
0
def analyse_cna_adaptive(atoms, mode="total"):
    """
    Use common neighbor analysis

    Args:
        atoms (pyiron.structure.atoms.Atoms): The structure to analyze.
        mode ("total"/"numeric"/"str"): Controls the style and level
        of detail of the output.
        total : return number of atoms belonging to each structure
        numeric : return a per atom list of numbers- 0 for unknown,
            1 fcc, 2 hcp, 3 bcc and 4 icosa
        str : return a per atom string of sructures

    Returns:
        (depends on `mode`)
    """
    if not mode in ["total", "numeric", "str"]:
        raise ValueError("Unsupported mode")

    sys = pc.System()
    sys.read_inputfile(atoms, format="ase")
    cna = sys.calculate_cna(cutoff=None)

    if mode == "total":
        return cna
    else:
        atoms = sys.atoms
        cnalist = ([atom.structure for atom in atoms])
        if mode == "numeric":
            return cnalist
        else:
            dd = ["unknown", "fcc", "hcp", "bcc", "ico"]
            cnalist = [dd[int(x)] for x in cnalist]
            return cnalist
Пример #12
0
def test_entropy():
    sys = pc.System()
    sys.read_inputfile("tests/conf.fcc.Al.dump")
    sys.find_neighbors(method="cutoff", cutoff=0)

    lat = (sys.box[0][0] / 5)

    sys.calculate_entropy(1.4 * lat,
                          ra=0.9 * lat,
                          averaged=True,
                          switching_function=True)
    atoms = sys.atoms
    solid_entropy = [atom.entropy for atom in atoms]
    solid_avg_entropy = [atom.avg_entropy for atom in atoms]
    #assert np.mean(solid_entropy) == 2
    assert np.abs(np.mean(solid_entropy) + 3.471) < 0.001
    assert np.abs(np.mean(solid_avg_entropy) + 3.471) < 0.001

    sys.calculate_entropy(1.4 * lat, averaged=True)
    atoms = sys.atoms
    solid_entropy = [atom.entropy for atom in atoms]
    solid_avg_entropy = [atom.avg_entropy for atom in atoms]
    #assert np.mean(solid_entropy) == 2
    assert np.abs(np.mean(solid_entropy) + 3.471) < 0.001
    assert np.abs(np.mean(solid_avg_entropy) + 3.471) < 0.001
Пример #13
0
def test_neighbors_system_filter():
    #create some atoms
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[2, 2, 2])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims

    sys.find_neighbors(method='cutoff', cutoff=0.867)
    #any atom should have 8 neighbors
    atoms = sys.atoms
    assert atoms[0].coordination == 8

    #now we take all the neighbors of atom0 and replace half of
    #them with a different type
    neighs = atoms[0].neighbors

    #replace the neighs
    atoms[neighs[0]].type = 2
    atoms[neighs[1]].type = 2

    #now set these atoms back
    #for atom in atoms:
    sys.set_atom(atoms[neighs[0]])
    sys.set_atom(atoms[neighs[1]])

    #recalculate neighbors with filter
    sys.find_neighbors(method='cutoff', cutoff=0.867, filter='type')
    #any atom should have 8 neighbors
    atoms = sys.atoms
    assert atoms[0].coordination == 6
Пример #14
0
def test_complex_system():
    sys = pc.System()
    sys.read_inputfile('examples/cluster.dump')
    sys.find_neighbors(method='cutoff', cutoff=3.63)
    assert 176 == sys.find_solids(bonds=6,
                                  threshold=0.5,
                                  avgthreshold=0.6,
                                  cluster=True)
Пример #15
0
def test_csm_ovito():
    sys = pc.System()
    sys.read_inputfile("tests/bcc.csm.dump", customkeys=["Centrosymmetry"])
    sys.calculate_centrosymmetry(nmax=8)
    atoms = sys.atoms
    ind = np.random.randint(0, len(atoms))
    assert np.abs(atoms[ind].centrosymmetry -
                  float(atoms[ind].custom["Centrosymmetry"])) < 1E-5
Пример #16
0
def test_basic_system():
    #basic system tests
    sys = pc.System()
    #sys.set_box([[0,1],[0,1],[0,1]])
    #assert sys.get_box() == [[0,1],[0,1],[0,1]]
    #sys.read_inputfile("conf.dump")
    #del sys
    pc.test()
Пример #17
0
def test_cubic():
    #this might take a while, it will find all qs
    atoms = bulk("Fe")
    sys = pc.System()
    sys.read_inputfile(atoms, format="ase")
    box, atoms = sys.extract_cubic_box()

    assert np.sum(np.array(atoms[0].pos)-np.array([0.0, 0.0, 0.0])) < 1E-10
    assert np.sum(np.array(atoms[1].pos)-np.array([1.435, 1.435, 1.435])) < 1E-10
Пример #18
0
def test_create_multislice_dump():
    """
    Create a multitest dump file and test it
    """
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[6, 6, 6])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims

    ptp.write_structure(sys, "tests/bcc1.dump")

    atoms2, boxdims2 = pcs.make_crystal('bcc', repetitions=[6, 6, 6])
    #modify the coordinates of one atom
    x = atoms2[0].pos
    x[0] += 0.01
    atoms2[0].pos = x
    assert len(atoms2) == 432
    #write it out
    sys2 = pc.System()
    sys2.atoms = atoms2
    sys2.box = boxdims2

    ptp.write_structure(sys2, "tests/bcc2.dump")

    #now merge the two dump files
    os.system("cat tests/bcc1.dump tests/bcc2.dump > tests/bcc3.dat")
    #os.remove("tests/bcc1.dump")
    #os.remove("tests/bcc2.dump")

    #now this file should have info of both - read it in
    sys3 = pc.System()
    sys3.read_inputfile("tests/bcc3.dat", frame=1)
    atoms = sys3.atoms
    assert len(atoms) == 432
    assert atoms[0].pos == [0.01, 0, 0]

    #now this file should have info of both - read it in
    sys4 = pc.System()
    sys4.read_inputfile("tests/bcc3.dat", frame=0)
    atoms = sys4.atoms
    assert atoms[0].pos == [0.0, 0, 0]

    #now cleanup
    os.remove("tests/bcc3.dat")
Пример #19
0
def analyse_cna_adaptive(atoms, mode="total", ovito_compatibility=False):
    """
    Use common neighbor analysis

    Args:
        atoms (pyiron_atomistics.structure.atoms.Atoms): The structure to analyze.
        mode ("total"/"numeric"/"str"): Controls the style and level
            of detail of the output.
            - total : return number of atoms belonging to each structure
            - numeric : return a per atom list of numbers- 0 for unknown,
                1 fcc, 2 hcp, 3 bcc and 4 icosa
            - str : return a per atom string of sructures
        ovito_compatibility(bool): use ovito compatiblity mode

    Returns:
        (depends on `mode`)
    """
    s.publication_add(publication())
    if mode not in ["total", "numeric", "str"]:
        raise ValueError("Unsupported mode")

    pyscal_parameter = ['others', 'fcc', 'hcp', 'bcc', 'ico']
    ovito_parameter = [
        'CommonNeighborAnalysis.counts.OTHER',
        'CommonNeighborAnalysis.counts.FCC',
        'CommonNeighborAnalysis.counts.HCP',
        'CommonNeighborAnalysis.counts.BCC',
        'CommonNeighborAnalysis.counts.ICO'
    ]

    sys = pc.System()
    sys.read_inputfile(atoms, format="ase")
    cna = sys.calculate_cna()

    if mode == "total":
        if not ovito_compatibility:
            return cna
        else:
            return {o: cna[p] for o, p in zip(
                ovito_parameter,
                pyscal_parameter
            )}
    else:
        atoms = sys.atoms
        cnalist = np.array([atom.structure for atom in atoms])
        if mode == "numeric":
            return cnalist
        elif mode == "str":
            if not ovito_compatibility:
                dd = ['others', 'fcc', 'hcp', 'bcc', 'ico']
                return np.array([dd[int(x)] for x in cnalist])
            else:
                dd = ['Other', "FCC", "HCP", "BCC", "ICO"]
                return np.array([dd[int(x)] for x in cnalist])
        else:
            raise ValueError("Only total, str and numeric mode is imported for analyse_cna_adaptive()")
Пример #20
0
def test_voro_props():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[10, 10, 10])
    sys = pc.System()
    sys.box = boxdims
    sys.atoms = atoms

    sys.find_neighbors(method='voronoi')
    sys.calculate_vorovector()
    atoms = sys.atoms
    atom = atoms[0]
Пример #21
0
def test_cna_cutoff():
    atoms, box = pcs.make_crystal(structure="fcc",
                                  repetitions=(7, 7, 7),
                                  lattice_constant=4.00,
                                  noise=0.01)
    sys = pc.System()
    sys.atoms = atoms
    sys.box = box
    vec = sys.calculate_cna(cutoff=0.8536 * 4.1)
    assert vec[1] == 7 * 7 * 7 * 4
Пример #22
0
def test_rdf():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [4, 4, 4])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims
    rdf, r = sys.calculate_rdf()

    args = np.argsort(rdf)
    assert(np.round(r[args][-1], decimals=2) == 0.87)

    #test for an fcc type
    atoms, boxdims = pcs.make_crystal('fcc', repetitions = [4, 4, 4])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims
    rdf, r = sys.calculate_rdf()

    args = np.argsort(rdf)
    assert(np.round(r[args][-1], decimals=2) == 0.69)
Пример #23
0
def test_cutoff():
    atoms, box = pcs.make_crystal(structure="fcc",
                                  lattice_constant=4.07,
                                  repetitions=(6, 6, 6))
    sys = pc.System()
    sys.box = box
    sys.atoms = atoms
    sys.find_neighbors(method="cutoff", cutoff=0)
    sys.set_atom_cutoff(factor=2)
    atoms = sys.atoms
    assert (atoms[0].cutoff - 5.755849198858498) < 1E-5
Пример #24
0
def test_angular():
    atoms, boxdims = pcs.make_crystal('diamond', repetitions=[4, 4, 4])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims

    sys.find_neighbors(method='voronoi')
    sys.calculate_angularcriteria()

    q = [atom.angular for atom in sys.atoms]
    assert np.round(np.mean(np.array(q)), decimals=2) == 0.00
Пример #25
0
def test_triclinic_frames():

    os.system(
        "cat tests/conf.primitive.bcc.supercell.dump tests/conf.primitive.bcc.supercell.dump > tests/bcc.prim.dat"
    )
    sys3 = pc.System()
    sys3.read_inputfile("tests/bcc.prim.dat")
    sys3.find_neighbors(method='cutoff', cutoff=0.9)
    atoms = sys3.atoms
    neighs = atoms[0].neighbors
    assert len(neighs) == 8
Пример #26
0
def test_q_list():
    #this might take a while, it will find all qs
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[4, 4, 4])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims

    sys.find_neighbors(method='voronoi')

    sys.calculate_q([2, 4], averaged=True)
    q = sys.get_qvals([2, 4], averaged=True)
Пример #27
0
def test_q_10():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [4, 4, 4])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims

    sys.find_neighbors(method = 'voronoi')

    sys.calculate_q(10, averaged=True)
    q = sys.get_qvals(10, averaged=True)
    assert np.round(np.mean(np.array(q)), decimals=2) == 0.41
Пример #28
0
def test_q_4():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [4, 4, 4])
    sys = pc.System()
    sys.atoms = atoms
    sys.box = boxdims

    #sys.get_neighbors(method = 'voronoi')
    sys.find_neighbors(method = 'cutoff', cutoff=0.9)
    sys.calculate_q(4, averaged=True)
    q = sys.get_qvals(4, averaged=True)
    assert np.round(np.mean(np.array(q)), decimals=2) == 0.51 , "Calculated q4 value is wrong!"
Пример #29
0
def test_ordered_disorder():
    sys = pc.System()
    sys.read_inputfile('examples/conf.fcc.dump')
    sys.find_neighbors(method='cutoff', cutoff=0)
    sys.calculate_q(6)
    sys.calculate_disorder(averaged=True)
    atoms = sys.atoms
    disorder = [atom.disorder for atom in atoms]
    assert np.mean(disorder) < 0.50

    disorder = [atom.avg_disorder for atom in atoms]
    assert np.mean(disorder) < 0.50
Пример #30
0
def test_chiparamsbcc():
    atoms, box = pcs.make_crystal('bcc',
                                  repetitions=[3, 3, 3],
                                  lattice_constant=4)
    sys = pc.System()
    sys.box = box
    sys.atoms = atoms
    sys.find_neighbors(method='cutoff', cutoff=0)
    sys.calculate_chiparams()
    atoms = sys.atoms
    chip = atoms[2].chiparams
    assert chip == [3, 0, 0, 0, 36, 12, 0, 36, 0]