Ejemplo n.º 1
0
quip_client = QUIPClient(client_id=0,
                         exe=os.path.join(os.environ['QUIP_ROOT'],
                                          'build.' + os.environ['QUIP_ARCH'],
                                          'socktest'),
                         param_files=['params.xml'],
                         env=os.environ)

sock_calc = SocketCalculator(quip_client)

el = 'Si'
a0 = 5.43
n = [6, 4, 1]
crack_surface = [1, 1, 1]
crack_front = [1, -1, 0]

cryst = diamond(el, a0, n, crack_surface, crack_front)
cryst.pbc = [True, True, True]  # QUIP doesn't handle open BCs
cryst.rattle(0.01)

cryst.set_calculator(sock_calc)
sock_e = cryst.get_potential_energy()
sock_f = cryst.get_forces()
sock_s = cryst.get_stress()
sock_calc.shutdown()

# compare to results from quippy
quippy_calc = Potential('IP SW', param_filename='params.xml')
cryst.set_calculator(quippy_calc)
quippy_e = cryst.get_potential_energy()
quippy_f = cryst.get_forces()
quippy_s = cryst.get_stress()
Ejemplo n.º 2
0
        def test_embedding_size_convergence(self):
            calc = Tersoff(**Tersoff_PRB_39_5566_Si_C)

            el = 'C'
            a0 = 3.566
            surface_energy = 2.7326 * 10
            crack_surface = [1, 1, 1]
            crack_front = [1, -1, 0]
            skin_x, skin_y = 1, 1

            cryst = bulk(el, cubic=True)
            cryst.set_calculator(calc)
            FIRE(UnitCellFilter(cryst), logfile=None).run(fmax=1e-6)
            a0 = cryst.cell.diagonal().mean()
            bondlength = cryst.get_distance(0, 1)
            #print('a0 =', a0, ', bondlength =', bondlength)

            cryst = diamond(el, a0, [1, 1, 1], crack_surface, crack_front)
            cryst.set_pbc(True)
            cryst.set_calculator(calc)
            cryst.set_cell(cryst.cell.diagonal(), scale_atoms=True)

            C, C_err = fit_elastic_constants(cryst,
                                             verbose=False,
                                             symmetry='cubic',
                                             optimizer=FIRE,
                                             fmax=1e-6)
            #print('Measured elastic constants (in GPa):')
            #print(np.round(C*10/units.GPa)/10)

            bondlengths = []
            refcell = None
            reftip_x = None
            reftip_y = None
            #[41, 39, 1],
            for i, n in enumerate([[21, 19, 1], [11, 9, 1], [6, 5, 1]]):
                #print(n)
                cryst = diamond(el, a0, n, crack_surface, crack_front)
                set_groups(cryst, n, skin_x, skin_y)
                cryst.set_pbc(True)
                cryst.set_calculator(calc)
                FIRE(UnitCellFilter(cryst), logfile=None).run(fmax=1e-6)
                cryst.set_cell(cryst.cell.diagonal(), scale_atoms=True)

                ase.io.write('cryst_{}.xyz'.format(i), cryst, format='extxyz')

                crk = crack.CubicCrystalCrack(crack_surface,
                                              crack_front,
                                              Crot=C / units.GPa)
                k1g = crk.k1g(surface_energy)

                tip_x = cryst.cell.diagonal()[0] / 2
                tip_y = cryst.cell.diagonal()[1] / 2

                a = cryst.copy()
                a.set_pbc([False, False, True])

                k1 = 1.0
                ux, uy = crk.displacements(cryst.positions[:, 0],
                                           cryst.positions[:, 1], tip_x, tip_y,
                                           k1 * k1g)

                a.positions[:, 0] += ux
                a.positions[:, 1] += uy

                # Center notched configuration in simulation cell and ensure enough vacuum.
                oldr = a[0].position.copy()
                if refcell is None:
                    a.center(vacuum=10.0, axis=0)
                    a.center(vacuum=10.0, axis=1)
                    refcell = a.cell.copy()
                    tip_x += a[0].x - oldr[0]
                    tip_y += a[0].y - oldr[1]
                    reftip_x = tip_x
                    reftip_y = tip_y
                else:
                    a.set_cell(refcell)

                # Shift tip position so all systems are exactly centered at the same spot
                a.positions[:, 0] += reftip_x - tip_x
                a.positions[:, 1] += reftip_y - tip_y

                refpositions = a.positions.copy()

                # Move reference crystal by same amount
                cryst.set_cell(a.cell)
                cryst.set_pbc([False, False, True])
                cryst.translate(a[0].position - oldr)

                bond1, bond2 = crack.find_tip_coordination(
                    a, bondlength=bondlength * 1.2)

                # Groups mark the fixed region and the region use for fitting the crack tip.
                g = a.get_array('groups')
                gcryst = cryst.get_array('groups')

                ase.io.write('cryst_{}.xyz'.format(i), cryst)

                a.set_calculator(calc)
                a.set_constraint(FixAtoms(mask=g == 0))
                FIRE(a, logfile=None).run(fmax=1e-6)

                dpos = np.sqrt((
                    (a.positions[:, 0] - refpositions[:, 0]) / ux)**2 + (
                        (a.positions[:, 1] - refpositions[:, 1]) / uy)**2)
                a.set_array('dpos', dpos)

                distance_from_tip = np.sqrt((a.positions[:, 0] - reftip_x)**2 +
                                            (a.positions[:, 1] - reftip_y)**2)

                ase.io.write('crack_{}.xyz'.format(i), a)

                # Compute average bond length per atom
                neighi, neighj, neighd = neighbour_list('ijd',
                                                        a,
                                                        cutoff=bondlength *
                                                        1.2)
                coord = np.bincount(neighi)
                assert coord.max() == 4

                np.savetxt(
                    'dpos_{}.out'.format(i),
                    np.transpose(
                        [distance_from_tip[coord == 4], dpos[coord == 4]]))

                # Compute distances from tipcenter
                neighdist = np.sqrt((
                    (a.positions[neighi, 0] + a.positions[neighj, 0]) / 2 -
                    reftip_x)**2 + (
                        (a.positions[neighi, 1] + a.positions[neighj, 1]) / 2 -
                        reftip_y)**2)

                np.savetxt('bl_{}.out'.format(i),
                           np.transpose([neighdist, neighd]))

                bondlengths += [a.get_distance(bond1, bond2)]
            print(bondlengths, np.diff(bondlengths),
                  bondlengths / bondlengths[-1] - 1)
            assert np.all(np.diff(bondlengths) > 0)
            assert np.max(bondlengths / bondlengths[0] - 1) < 0.01
Ejemplo n.º 3
0
surface_energy  = 1.08  * 10    # GPa*A = 0.1 J/m^2

# Crack system
n               = [ 4, 6, 1 ]
crack_surface   = [ 1,-1, 0 ]
crack_front     = [ 1, 1, 0 ]
crack_tip       = [ 41, 56 ]
skin_x, skin_y = 1, 1

vacuum          = 6.0

# Simulation control
nsteps          = 31
# Increase stress intensity factor
k1              = np.linspace(0.8, 1.5, nsteps)
# Don't move crack tip
tip_dx          = np.zeros_like(k1)
tip_dz          = np.zeros_like(k1)

fmax            = 0.05

# Setup crack system
cryst = diamond(el, a0, n, crack_surface, crack_front)
set_groups(cryst, n, skin_x, skin_y)

ase.io.write('cryst.cfg', cryst)

# Compute crack tip position
r0 = np.sum(cryst.get_positions()[crack_tip,:], axis=0)/len(crack_tip)
tip_x0, tip_y0, tip_z0 = r0
Ejemplo n.º 4
0
        def test_embedding_size_convergence(self):
            calc = Tersoff(**Tersoff_PRB_39_5566_Si_C)

            el = 'C'
            a0 = 3.566
            surface_energy = 2.7326 * 10
            crack_surface = [1, 1, 1]
            crack_front = [1, -1, 0]
            skin_x, skin_y = 1, 1

            cryst = bulk(el, cubic=True)
            cryst.set_calculator(calc)
            FIRE(UnitCellFilter(cryst), logfile=None).run(fmax=1e-6)
            a0 = cryst.cell.diagonal().mean()
            bondlength = cryst.get_distance(0, 1)
            #print('a0 =', a0, ', bondlength =', bondlength)

            cryst = diamond(el, a0, [1,1,1], crack_surface, crack_front)
            cryst.set_pbc(True)
            cryst.set_calculator(calc)
            cryst.set_cell(cryst.cell.diagonal(), scale_atoms=True)

            C, C_err = fit_elastic_constants(cryst, verbose=False,
                                             symmetry='cubic',
                                             optimizer=FIRE,
                                             fmax=1e-6)
            #print('Measured elastic constants (in GPa):')
            #print(np.round(C*10/units.GPa)/10)

            bondlengths = []
            refcell = None
            reftip_x = None
            reftip_y = None
            #[41, 39, 1], 
            for i, n in enumerate([[21, 19, 1], [11, 9, 1], [6, 5, 1]]):
                #print(n)
                cryst = diamond(el, a0, n, crack_surface, crack_front)
                set_groups(cryst, n, skin_x, skin_y)
                cryst.set_pbc(True)
                cryst.set_calculator(calc)
                FIRE(UnitCellFilter(cryst), logfile=None).run(fmax=1e-6)
                cryst.set_cell(cryst.cell.diagonal(), scale_atoms=True)

                ase.io.write('cryst_{}.xyz'.format(i), cryst, format='extxyz')

                crk = crack.CubicCrystalCrack(crack_surface,
                                              crack_front,
                                              Crot=C/units.GPa)
                k1g = crk.k1g(surface_energy)

                tip_x = cryst.cell.diagonal()[0]/2
                tip_y = cryst.cell.diagonal()[1]/2

                a = cryst.copy()
                a.set_pbc([False, False, True])

                k1 = 1.0
                ux, uy = crk.displacements(cryst.positions[:,0], cryst.positions[:,1],
                                           tip_x, tip_y, k1*k1g)

                a.positions[:, 0] += ux
                a.positions[:, 1] += uy

                # Center notched configuration in simulation cell and ensure enough vacuum.
                oldr = a[0].position.copy()
                if refcell is None:
                    a.center(vacuum=10.0, axis=0)
                    a.center(vacuum=10.0, axis=1)
                    refcell = a.cell.copy()
                    tip_x += a[0].x - oldr[0]
                    tip_y += a[0].y - oldr[1]
                    reftip_x = tip_x
                    reftip_y = tip_y
                else:
                    a.set_cell(refcell)

                # Shift tip position so all systems are exactly centered at the same spot
                a.positions[:, 0] += reftip_x - tip_x
                a.positions[:, 1] += reftip_y - tip_y

                refpositions = a.positions.copy()

                # Move reference crystal by same amount
                cryst.set_cell(a.cell)
                cryst.set_pbc([False, False, True])
                cryst.translate(a[0].position - oldr)

                bond1, bond2 = crack.find_tip_coordination(a, bondlength=bondlength*1.2)

                # Groups mark the fixed region and the region use for fitting the crack tip.
                g = a.get_array('groups')
                gcryst = cryst.get_array('groups')

                ase.io.write('cryst_{}.xyz'.format(i), cryst)

                a.set_calculator(calc)
                a.set_constraint(FixAtoms(mask=g==0))
                FIRE(a, logfile=None).run(fmax=1e-6)

                dpos = np.sqrt(((a.positions[:, 0]-refpositions[:, 0])/ux)**2 + ((a.positions[:, 1]-refpositions[:, 1])/uy)**2)
                a.set_array('dpos', dpos)

                distance_from_tip = np.sqrt((a.positions[:, 0]-reftip_x)**2 + (a.positions[:, 1]-reftip_y)**2)

                ase.io.write('crack_{}.xyz'.format(i), a)

                # Compute average bond length per atom
                neighi, neighj, neighd = neighbour_list('ijd', a, cutoff=bondlength*1.2)
                coord = np.bincount(neighi)
                assert coord.max() == 4

                np.savetxt('dpos_{}.out'.format(i), np.transpose([distance_from_tip[coord==4], dpos[coord==4]]))

                # Compute distances from tipcenter
                neighdist = np.sqrt(((a.positions[neighi,0]+a.positions[neighj,0])/2-reftip_x)**2 +
                                    ((a.positions[neighi,1]+a.positions[neighj,1])/2-reftip_y)**2)

                np.savetxt('bl_{}.out'.format(i), np.transpose([neighdist, neighd]))

                bondlengths += [a.get_distance(bond1, bond2)]
            print(bondlengths, np.diff(bondlengths), bondlengths/bondlengths[-1]-1)
            assert np.all(np.diff(bondlengths) > 0)
            assert np.max(bondlengths/bondlengths[0]-1) < 0.01