def test_pyscf(): """ Take ASE Diamond structure, input into PySCF and run """ ase_atom=Diamond(symbol='C', latticeconstant=3.5668) print ase_atom.get_volume() cell = pbcgto.Cell() cell.atom=pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.h=ase_atom.cell cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' #cell.gs=np.array([10,10,10]) cell.gs=np.array([20,20,20]) cell.verbose=7 cell.build(None,None) print cell._atom print "Cell nimgs =", cell.nimgs print "Cell _basis =", cell._basis print "Cell _pseudo =", cell._pseudo print "Cell nelectron =", cell.nelectron mf=pbcdft.RKS(cell) mf.xc='lda,vwn' mf.analytic_int=False print mf.scf() # [10,10,10]: -44.8811199336
def test_cubic_diamond_C(): """ Take ASE Diamond structure, input into PySCF and run """ ase_atom = Diamond(symbol='C', latticeconstant=3.5668) print "Cell volume =", ase_atom.get_volume() cell = pbcgto.Cell() cell.atom = pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.h = ase_atom.cell cell.basis = "gth-szv" cell.pseudo = "gth-pade" cell.gs = np.array([10,10,10]) # cell.verbose = 7 cell.build(None, None) mf = pbcdft.RKS(cell) mf.analytic_int = False mf.xc = 'lda,vwn' print mf.scf() # Gamma point gs: 10x10x10: -11.220279983393 # gs: 14x14x14: -11.220122248175 # K pt calc scaled_kpts = ase.dft.kpoints.monkhorst_pack((2,2,2)) abs_kpts = cell.get_abs_kpts(scaled_kpts) kmf = pyscf.pbc.scf.kscf.KRKS(cell, abs_kpts) kmf.analytic_int = False kmf.xc = 'lda,vwn' kmf.verbose = 7 print kmf.scf()
def test_cubic_diamond_C(): """ Take ASE Diamond structure, input into PySCF and run """ ase_atom = Diamond(symbol='C', latticeconstant=3.5668) print "Cell volume =", ase_atom.get_volume() cell = pbcgto.Cell() cell.atom = pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.a = ase_atom.cell cell.basis = "gth-szv" cell.pseudo = "gth-pade" cell.gs = np.array([10, 10, 10]) # cell.verbose = 7 cell.build(None, None) mf = pbcdft.RKS(cell) mf.analytic_int = False mf.xc = 'lda,vwn' print mf.scf() # Gamma point gs: 10x10x10: -11.220279983393 # gs: 14x14x14: -11.220122248175 # K pt calc scaled_kpts = ase.dft.kpoints.monkhorst_pack((2, 2, 2)) abs_kpts = cell.get_abs_kpts(scaled_kpts) kmf = pyscf.pbc.scf.kscf.KRKS(cell, abs_kpts) kmf.analytic_int = False kmf.xc = 'lda,vwn' kmf.verbose = 7 print kmf.scf()
def make_dia_100_cell(size=(1, 1, 1), symbols=['Ni'], pbc=(1, 1, 1)): direction_x = [1, 0, 0] direction_y = [0, 1, 0] direction_z = [0, 0, 1] atoms = None try: atoms = Diamond(\ directions=[direction_x,direction_y,direction_z], size=size, symbol=symbols[0], pbc=pbc) except ValueError as e: if str( e ) == 'Cannot guess the diamond lattice constant of an element with crystal structure fcc.': r = get_atomic_radius(symbol=symbols[0]) a0 = 3.567 atoms = Diamond(\ directions=[direction_x,direction_y,direction_z], size=size, symbol=symbols[0], pbc=pbc, latticeconstant=a0) else: raise ValueError("cannnot create the diamond cubic structure") return atoms
def testForceAgainstDefaultNeighborList(self): atoms = Diamond(symbol="C", pbc=False) builtin = torchani.neurochem.Builtins() calculator = torchani.ase.Calculator(builtin.species, builtin.aev_computer, builtin.models, builtin.energy_shifter) default_neighborlist_calculator = torchani.ase.Calculator( builtin.species, builtin.aev_computer, builtin.models, builtin.energy_shifter, True) atoms.set_calculator(calculator) dyn = Langevin(atoms, 5 * units.fs, 50 * units.kB, 0.002) def test_energy(a=atoms): a = a.copy() a.set_calculator(calculator) e1 = a.get_potential_energy() a.set_calculator(default_neighborlist_calculator) e2 = a.get_potential_energy() self.assertLess(abs(e1 - e2), tol) dyn.attach(test_energy, interval=1) dyn.run(500)
def testEqualOneModelPTI(self): calculator_pti = self.model_pti[0].ase() calculator = self.model[0].ase() atoms = Diamond(symbol="C", pbc=True) atoms_pti = Diamond(symbol="C", pbc=True) atoms.set_calculator(calculator) atoms_pti.set_calculator(calculator_pti) self.assertEqual(atoms.get_potential_energy(), atoms_pti.get_potential_energy())
def get_ase_diamond_cubic(atom='C'): """Get the ASE atoms for cubic (8-atom) diamond unit cell.""" from ase.lattice.cubic import Diamond if atom == 'C': ase_atom = Diamond(symbol='C', latticeconstant=3.5668*A2B) else: ase_atom = Diamond(symbol='Si', latticeconstant=5.431*A2B) return ase_atom
def get_ase_diamond_cubic(atom='C'): """Get the ASE atoms for cubic (8-atom) diamond unit cell.""" from ase.lattice.cubic import Diamond if atom == 'C': ase_atom = Diamond(symbol='C', latticeconstant=3.5668*A2B) elif atom == 'Si': ase_atom = Diamond(symbol='Si', latticeconstant=5.431*A2B) else: raise NotImplementedError('No formula found for system ', atom, '. Choose a different system? Or add it to the list!') return ase_atom
def testWithNumericalForceWithPBCEnabled(self): # Run a Langevin thermostat dynamic for 100 steps and after the dynamic # check once that the numerical and analytical force agree to a given # relative tolerance atoms = Diamond(symbol="C", pbc=True) calculator = self.model.ase() atoms.set_calculator(calculator) dyn = Langevin(atoms, 5 * units.fs, 30000000 * units.kB, 0.002) dyn.run(100) f = atoms.get_forces() fn = get_numeric_force(atoms, 0.001) self.assertEqual(f, fn, rtol=0.1, atol=0.1)
def testWithNumericalForceWithPBCEnabled(self): atoms = Diamond(symbol="C", pbc=True) calculator = torchani.models.ANI1x().ase() atoms.set_calculator(calculator) dyn = Langevin(atoms, 5 * units.fs, 30000000 * units.kB, 0.002) dyn.run(100) f = torch.from_numpy(atoms.get_forces()) fn = get_numeric_force(atoms, 0.001) df = (f - fn).abs().max() avgf = f.abs().mean() if avgf > 0: self.assertLess(df / avgf, 0.1)
def test_dsygv_dgelsd(self): a = Diamond('C', size=[4,4,4]) b = a.copy() b.positions += (np.random.random(b.positions.shape)-0.5)*0.1 i, j = neighbour_list("ij", b, 1.85) dr_now = mic(b.positions[i] - b.positions[j], b.cell) dr_old = mic(a.positions[i] - a.positions[j], a.cell) dgrad1 = get_delta_plus_epsilon_dgesv(len(b), i, dr_now, dr_old) dgrad2 = get_delta_plus_epsilon(len(b), i, dr_now, dr_old) self.assertArrayAlmostEqual(dgrad1, dgrad2)
def build_surface(self, pot, size=(1, 1, 1)): """ Create an equivalent surface unit cell for the fracture system. """ if self.symbol == 'Si': unit_slab = Diamond(directions=[ self.crack_direction, self.cleavage_plane, self.crack_front ], size=size, symbol=self.symbol, pbc=True, latticeconstant=self.a0) elif self.symbol == 'Fe': unit_slab = BodyCenteredCubic(directions=[ self.crack_direction, self.cleavage_plane, self.crack_front ], size=size, symbol='Fe', pbc=(1, 1, 1), latticeconstant=self.a0) # Does this work for more than 2 atoms? unit_slab.info['adsorbate_info'] = None unit_slab.positions[:, 1] += (unit_slab.positions[1, 1] - unit_slab.positions[0, 1]) / 2.0 unit_slab.set_scaled_positions(unit_slab.get_scaled_positions()) surface = unit_slab.copy() surface.center(vacuum=self.vacuum, axis=1) surface.set_calculator(pot) return surface
def dia_111(sym, a0): sym = string2symbols(sym) if len(sym) == 1: a = Diamond(sym[0], size=[nx, nx, nz], latticeconstant=a0, directions=[[1, -1, 0], [1, 1, -2], [1, 1, 1]]) else: a = B3(sym, size=[nx, nx, nz], latticeconstant=a0, directions=[[1, -1, 0], [1, 1, -2], [1, 1, 1]]) sx, sy, sz = a.get_cell().diagonal() a.translate([sx / (12 * nx), sy / (4 * nx), sz / (12 * nz)]) return a
def _testForce(self, pbc): atoms = Diamond(symbol="C", pbc=pbc) builtin = torchani.neurochem.Builtins() calculator = torchani.ase.Calculator( builtin.species, builtin.aev_computer, builtin.models, builtin.energy_shifter) atoms.set_calculator(calculator) dyn = Langevin(atoms, 5 * units.fs, 30000000 * units.kB, 0.002) dyn.run(100) f = torch.from_numpy(atoms.get_forces()) fn = get_numeric_force(atoms, 0.001) df = (f - fn).abs().max() avgf = f.abs().mean() if avgf > 0: self.assertLess(df / avgf, 0.1)
def test_hydrogenate(self): a = Diamond('Si', size=[2, 2, 1]) b = hydrogenate(a, 2.85, 1.0, mask=[True, True, False], vacuum=5.0) # Check if every atom is fourfold coordinated syms = np.array(b.get_chemical_symbols()) c = np.bincount(neighbour_list('i', b, 2.4)) self.assertTrue((c[syms != 'H'] == 4).all())
def dia_111(sym, a0): sym = string2symbols(sym) if len(sym) == 1: a = Diamond(sym[0], size = [nx, nx, nz], latticeconstant = a0, directions=[ [1,-1,0], [1,1,-2], [1,1,1] ] ) else: a = B3(sym, size = [nx, nx, nz], latticeconstant = a0, directions=[ [1,-1,0], [1,1,-2], [1,1,1] ] ) sx, sy, sz = a.get_cell().diagonal() a.translate([sx/(12*nx), sy/(4*nx), sz/(12*nz)]) return a
def __init__(self, a0, nlayers, *args, **kwargs): self.atoms = Diamond(symbol="Sn", latticeconstant=a0, directions=[[1, -2, 0], [0, 0, -1], [2, 1, 0]], size=(1, 1, nlayers), pbc=(1, 1, 0), miller=[None, None, [2, 1, 1]]) super().__init__(**{"a0": a0})
def main(): for x in fccs+bccs+hcps+diamonds+rocksalts+zincblendes+cscls: f = x in fccs b = x in bccs h = x in hcps d = x in diamonds r = x in rocksalts z = x in zincblendes c = x in cscls try: if f: a = FaceCenteredCubic(x[0]).get_cell()[0][0]/2 elif b: a = BodyCenteredCubic(x[0]).get_cell()[0][0]/2 elif d: a = Diamond(x[0]).get_cell()[0][0]/2 elif h: cell = HexagonalClosedPacked(x[0]).get_cell() a,c = cell[0][0],cell[2][2] elif r | z | c: a = dataLookup(x[0]) else: raise NotImplementedError except ValueError: a = sum([radDict[e] for e in elems])/len(elems) print "Had to guess lattice constant of "+x[0] if f: name,struc,pos,cell,n = '-fcc', 'fcc', [[0,0,0]], [[0,a,a],[a,0,a],[a,a,0]], 1 elif b: name,struc,pos,cell,n = '-bcc', 'bcc', [[0,0,0]], [[a,a,-a],[-a,a,a],[a,-a,a]],1 elif h: name,struc,pos,cell,n = '-hcp', 'hexagonal', [[0,0,0],[2./3,1./3,1./2]], [a,a,c,90,90,120], 2 elif d: name,struc,pos,cell,n = '-diamond', 'diamond', [[0,0,0],[0.25,0.25,0.25]], [[0,a,a],[a,0,a],[a,a,0]], 2 elif z: name,struc,pos,cell,n = '-zincblende','zincblende', [[0,0,0],[0.25,0.25,0.25]], [[0,a,a],[a,0,a],[a,a,0]], 1 elif r: name,struc,pos,cell,n = '-rocksalt', 'rocksalt', [[0,0,0],[0.5,0.5,0.5]], [[0,a,a],[a,0,a],[a,a,0]], 1 elif c: name,struc,pos,cell,n = '-cscl', 'cubic', [[0,0,0],[0.5,0.5,0.5]], [a,a,a,90,90,90], 1 mag = magLookup(x[0]) elems = parseChemicalFormula(x[0]).keys()*n magmoms = [magmomInit if e in magElems else 0 for e in elems] atoms = Atoms(elems,scaled_positions=pos,cell=cell,pbc=[1,1,1],magmoms=magmoms,calculator=EMT()) info = {'name': x[0]+name ,'relaxed': False ,'emt': atoms.get_potential_energy()/len(elems) #normalized to per-atom basis ,'comments': 'Autogenerated by createTrajs' ,'kind': 'bulk' # vs surface/molecules ### Stuff for bulk ,'structure': struc ### Stuff for surfaces ,'parent': None ,'sites': None ,'facet': None ,'xy': None ,'layers': None ,'constrained': None ,'symmetric': None ,'vacuum': None ,'adsorbates': None} db.write(atoms,key_value_pairs=info)
def build_unit_slab(self, size=(1, 1, 1)): """ Initialize the unit slab for the given crack geometry. Currently supports silicon and Fe. """ if self.symbol == 'Si': unit_slab = Diamond(directions=[ self.crack_direction, self.cleavage_plane, self.crack_front ], size=size, symbol=self.symbol, pbc=True, latticeconstant=self.a0) elif self.symbol == 'Fe': unit_slab = BodyCenteredCubic(directions=[ self.crack_direction, self.cleavage_plane, self.crack_front ], size=size, symbol='Fe', pbc=(1, 1, 1), latticeconstant=self.a0) print 'Number atoms in unit slab', len(unit_slab) unit_slab.info['adsorbate_info'] = None unit_slab.positions[:, 1] += (unit_slab.positions[1, 1] - unit_slab.positions[0, 1]) / 2.0 unit_slab.set_scaled_positions(unit_slab.get_scaled_positions()) pot_dir = os.environ['POTDIR'] pot_file = os.path.join(pot_dir, self.param_file) print pot_file print self.mm_init_args #pot = Potential(self.mm_init_args, param_filename = pot_file) #pot = Potential("IP EAM_ErcolAd do_rescale_r=T r_scale=1.00894848312" , param_filename = "/Users/lambert/pymodules/imeall/imeall/potentials/PotBH.xml") #unit_slab.set_calculator(pot) return unit_slab
def __init__(self, a0, nlayers, *args, **kwargs): self.atoms = Diamond(symbol="Sn", latticeconstant=a0, directions=[[1, -1, 0], [0, 0, -1], [1, 1, 0]], size=(1, 1, nlayers), pbc=(1, 1, 0), miller=[None, None, [1, 1, 0]]) # self.atoms = ase.build.cut(self.atoms, a=(1, 0, 0), b=(0, 1, 0), c=None, clength=None, origo=(0, 0, 0), nlayers=nlayers, extend=1.0, tolerance=0.01, maxatoms=None) super().__init__(**{"a0": a0})
def test_calculator(): """ Take ASE structure, PySCF object, and run through ASE calculator interface. This allows other ASE methods to be used with PySCF; here we try to compute an equation of state. """ ase_atom=Diamond(symbol='C', latticeconstant=3.5668) # Set up a cell; everything except atom; the ASE calculator will # set the atom variable cell = pbcgto.Cell() cell.h=ase_atom.cell cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.gs=np.array([8,8,8]) cell.verbose = 0 # Set up the kind of calculation to be done # Additional variables for mf_class are passed through mf_dict mf_class=pbcdft.RKS mf_dict = { 'xc' : 'lda,vwn' } # Once this is setup, ASE is used for everything from this point on ase_atom.set_calculator(pyscf_ase.PySCF(molcell=cell, mf_class=mf_class, mf_dict=mf_dict)) print "ASE energy", ase_atom.get_potential_energy() print "ASE energy (should avoid re-evaluation)", ase_atom.get_potential_energy() # Compute equation of state ase_cell=ase_atom.cell volumes = [] energies = [] for x in np.linspace(0.95, 1.2, 5): ase_atom.set_cell(ase_cell * x, scale_atoms = True) print "[x: %f, E: %f]" % (x, ase_atom.get_potential_energy()) volumes.append(ase_atom.get_volume()) energies.append(ase_atom.get_potential_energy()) eos = EquationOfState(volumes, energies) v0, e0, B = eos.fit() print(B / kJ * 1.0e24, 'GPa') eos.plot('eos.png')
def test_klda8_cubic_gamma(self): ase_atom = Diamond(symbol='C', latticeconstant=LATTICE_CONST) cell = build_cell(ase_atom, 8) mf = pbcdft.RKS(cell) mf.xc = 'lda,vwn' #kmf.verbose = 7 e1 = mf.scf() #print "mf._ecoul =", mf._ecoul #print "mf._exc =", mf._exc self.assertAlmostEqual(e1, -44.892502703975893, 8)
def dia_100_2x1(sym, a0): sym = string2symbols(sym) if len(sym) == 1: a = Diamond(sym[0], size = [2*nx, nx, nz], latticeconstant = a0, directions=[ [1,-1,0], [1,1,0], [0,0,1] ] ) else: a = B3(sym, size = [2*nx, nx, nz], latticeconstant = a0, directions=[ [1,-1,0], [1,1,0], [0,0,1] ] ) sx, sy, sz = a.get_cell().diagonal() a.translate([sx/(8*nx), sy/(8*nx), sz/(8*nz)]) bulk = a.copy() for i in a: if i.z < sz/(4*nz) or i.z > sz-sz/(4*nz): if i.x < sx/2: i.x = i.x+0.5 else: i.x = i.x-0.5 return bulk, a
def test_klda8_cubic_kpt_222(self): ase_atom = Diamond(symbol='C', latticeconstant=LATTICE_CONST) scaled_kpts = ase.dft.kpoints.monkhorst_pack((2, 2, 2)) cell = build_cell(ase_atom, 8) abs_kpts = cell.get_abs_kpts(scaled_kpts) mf = pbcdft.KRKS(cell, abs_kpts) #mf.analytic_int = False mf.xc = 'lda,vwn' #mf.verbose = 7 e1 = mf.scf() #print "mf._ecoul =", mf._ecoul #print "mf._exc =", mf._exc self.assertAlmostEqual(e1, -45.425834895129569, 8)
def test_sqlite(): print('test_single_file') try: os.remove('checkpoints.db') except OSError: pass CP = Checkpoint('checkpoints.db') a = Diamond('Si', size=[2, 2, 2]) a = CP(op1)(a, 1.0) op1a = a.copy() a, ra = CP(op2)(a, 2.0) op2a = a.copy() op2ra = ra.copy() CP = Checkpoint('checkpoints.db') a = Diamond('Si', size=[2, 2, 2]) a = CP(op1)(a, 1.0) assert a == op1a a, ra = CP(op2)(a, 2.0) assert a == op2a assert(np.abs(ra - op2ra).max() < 1e-5)
def test_sqlite(self): print('test_single_file') try: os.remove('checkpoints.db') except OSError: pass CP = Checkpoint('checkpoints.db') a = Diamond('Si', size=[2,2,2]) a = CP(self.op1)(a, 1.0) op1a = a.copy() a, ra = CP(self.op2)(a, 2.0) op2a = a.copy() op2ra = ra.copy() CP = Checkpoint('checkpoints.db') a = Diamond('Si', size=[2,2,2]) a = CP(self.op1)(a, 1.0) self.assertAtomsAlmostEqual(a, op1a) a, ra = CP(self.op2)(a, 2.0) self.assertAtomsAlmostEqual(a, op2a) self.assertArrayAlmostEqual(ra, op2ra)
def MD(): old_stdout = sys.stdout sys.stdout = mystdout = StringIO() orig_stdout = sys.stdout f = open('out.txt', 'w') sys.stdout = f #f = open('out_' + str(temp) + '.txt', 'w') #sys.stdout = f Tmin = 1000 Tmax = 15000 a0 = 5.43 N = 1 atoms = Diamond(symbol='Si', latticeconstant=a0) atoms *= (N, N, N) atoms.set_calculator(model.calculator) MaxwellBoltzmannDistribution(atoms, Tmin * units.kB) ###is this allowed? Stationary(atoms) # zero linear momentum ZeroRotation(atoms) def printenergy(a=atoms): epot = a.get_potential_energy() / len(a) ekin = a.get_kinetic_energy() / len(a) print(ekin) traj = Trajectory('Si.traj', 'w', atoms) for temp in np.linspace(Tmin, Tmax, 5): dyn = Langevin(atoms, 5 * units.fs, units.kB * temp, 0.002) dyn.attach(traj.write, interval=1) dyn.attach(printenergy, interval=1) dyn.run(100) sys.stdout = orig_stdout f.close()
def test_cubic_diamond_He(): """ Take ASE Diamond structure, input into PySCF and run """ ase_atom=Diamond(symbol='He', latticeconstant=3.5) print ase_atom.get_volume() cell = pbcgto.Cell() cell.atom=pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.h=ase_atom.cell.T cell.basis = {"He" : [[0, (1.0, 1.0)], [0, (0.8, 1.0)]] } cell.gs = np.array([15,15,15]) # cell.verbose = 7 cell.build(None, None) mf = pbcdft.RKS(cell) mf.analytic_int=False mf.xc = 'lda,vwn' print mf.scf() # Diamond cubic: -18.2278622592408 mf = pbcdft.RKS(cell) mf.analytic_int=True mf.xc = 'lda,vwn' print mf.scf() # Diamond cubic (analytic): -18.2278622592283 # = -4.556965564807075 / cell # K pt calc scaled_kpts=ase.dft.kpoints.monkhorst_pack((2,2,2)) abs_kpts=cell.get_abs_kpts(scaled_kpts) kmf = pyscf.pbc.scf.kscf.KRKS(cell, abs_kpts) kmf.analytic_int=False kmf.xc = 'lda,vwn' print kmf.scf()
def test_cubic_diamond_He(): """ Take ASE Diamond structure, input into PySCF and run """ ase_atom=Diamond(symbol='He', latticeconstant=3.5) print ase_atom.get_volume() cell = pbcgto.Cell() cell.atom=pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.h=ase_atom.cell cell.basis = {"He" : [[0, (1.0, 1.0)], [0, (0.8, 1.0)]] } cell.gs = np.array([15,15,15]) # cell.verbose = 7 cell.build(None, None) mf = pbcdft.RKS(cell) mf.analytic_int=False mf.xc = 'lda,vwn' print mf.scf() # Diamond cubic: -18.2278622592408 mf = pbcdft.RKS(cell) mf.analytic_int=True mf.xc = 'lda,vwn' print mf.scf() # Diamond cubic (analytic): -18.2278622592283 # = -4.556965564807075 / cell # K pt calc scaled_kpts=ase.dft.kpoints.monkhorst_pack((2,2,2)) abs_kpts=cell.get_abs_kpts(scaled_kpts) kmf = pyscf.pbc.scf.kscf.KRKS(cell, abs_kpts) kmf.analytic_int=False kmf.xc = 'lda,vwn' print kmf.scf()
def test_klda8_cubic_kpt_222(self): ase_atom = Diamond(symbol='C', latticeconstant=LATTICE_CONST) cell = pbcgto.Cell() cell.unit = 'A' cell.h = ase_atom.cell cell.gs = np.array([8]*3) cell.atom = pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.verbose = 5 cell.output = '/dev/null' cell.build() kpts = cell.make_kpts((2,2,2)) mf = pbcdft.KUKS(cell, kpts) mf.xc = 'lda,vwn' e1 = mf.scf() self.assertAlmostEqual(e1, -45.42583489512954, 8) self.assertAlmostEqual(mf._ecoul, 3.2519161200384685, 8) self.assertAlmostEqual(mf._exc, -13.937886385300949, 8)
def build_surface(self,pot, size=(1,1,1)): """ Create an equivalent surface unit cell for the fracture system. """ if self.symbol=='Si': unit_slab = Diamond(directions = [self.crack_direction, self.cleavage_plane, self.crack_front], size = size, symbol=self.symbol, pbc=True, latticeconstant= self.a0) elif self.symbol=='Fe': unit_slab = BodyCenteredCubic(directions=[self.crack_direction, self.cleavage_plane, self.crack_front], size=size, symbol='Fe', pbc=(1,1,1), latticeconstant=self.a0) # Does this work for more than 2 atoms? unit_slab.info['adsorbate_info'] = None unit_slab.positions[:, 1] += (unit_slab.positions[1, 1]-unit_slab.positions[0, 1])/2.0 unit_slab.set_scaled_positions(unit_slab.get_scaled_positions()) surface = unit_slab.copy() surface.center(vacuum=self.vacuum, axis=1) surface.set_calculator(pot) return surface
def test_sqlite(testdir): CP = Checkpoint('checkpoints.db') a = Diamond('Si', size=[2, 2, 2]) a = CP(op1)(a, 1.0) op1a = a.copy() a, ra = CP(op2)(a, 2.0) op2a = a.copy() op2ra = ra.copy() CP = Checkpoint('checkpoints.db') a = Diamond('Si', size=[2, 2, 2]) a = CP(op1)(a, 1.0) assert a == op1a a, ra = CP(op2)(a, 2.0) assert a == op2a assert(np.abs(ra - op2ra).max() < 1e-5)
def test_sqlite(self): print('test_single_file') try: os.remove('checkpoints.db') except OSError: pass CP = Checkpoint('checkpoints.db') a = Diamond('Si', size=[2, 2, 2]) a = CP(self.op1)(a, 1.0) op1a = a.copy() a, ra = CP(self.op2)(a, 2.0) op2a = a.copy() op2ra = ra.copy() CP = Checkpoint('checkpoints.db') a = Diamond('Si', size=[2, 2, 2]) a = CP(self.op1)(a, 1.0) self.assertEqual(a, op1a) a, ra = CP(self.op2)(a, 2.0) self.assertEqual(a, op2a) self.assert_(np.abs(ra - op2ra).max() < 1e-5)
def build_unit_slab(self, size=(1,1,1)): """ Initialize the unit slab for the given crack geometry. Currently supports silicon and Fe. """ if self.symbol=='Si': unit_slab = Diamond(directions = [self.crack_direction, self.cleavage_plane, self.crack_front], size = size, symbol=self.symbol, pbc=True, latticeconstant= self.a0) elif self.symbol=='Fe': unit_slab = BodyCenteredCubic(directions=[self.crack_direction, self.cleavage_plane, self.crack_front], size=size, symbol='Fe', pbc=(1,1,1), latticeconstant=self.a0) print 'Number atoms in unit slab', len(unit_slab) unit_slab.info['adsorbate_info'] = None unit_slab.positions[:, 1] += (unit_slab.positions[1, 1]-unit_slab.positions[0, 1])/2.0 unit_slab.set_scaled_positions(unit_slab.get_scaled_positions()) pot_dir = os.environ['POTDIR'] pot_file = os.path.join(pot_dir, self.param_file) print pot_file print self.mm_init_args #pot = Potential(self.mm_init_args, param_filename = pot_file) #pot = Potential("IP EAM_ErcolAd do_rescale_r=T r_scale=1.00894848312" , param_filename = "/Users/lambert/pymodules/imeall/imeall/potentials/PotBH.xml") #unit_slab.set_calculator(pot) return unit_slab
here we try to compute an equation of state. """ import numpy as np from pyscf.pbc.tools import pyscf_ase import pyscf.pbc.gto as pbcgto import pyscf.pbc.dft as pbcdft import ase import ase.lattice from ase.lattice.cubic import Diamond from ase.units import kJ from ase.utils.eos import EquationOfState ase_atom=Diamond(symbol='C', latticeconstant=3.5668) # Set up a cell; everything except atom; the ASE calculator will # set the atom variable cell = pbcgto.Cell() cell.a=ase_atom.cell cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.verbose = 0 # Set up the kind of calculation to be done # Additional variables for mf_class are passed through mf_dict # E.g. gamma-point SCF calculation can be set to mf_class = pbcdft.RKS # SCF with k-point sampling can be set to mf_class = lambda cell: pbcdft.KRKS(cell, kpts=cell.make_kpts([2,2,2]))
output_file = 'crack.xyz' # File to which structure will be written set_fortran_indexing(False) si_bulk = bulk('Si', 'diamond', a=5.431, cubic=True) mm_pot = Potential("IP SW") si_bulk.set_calculator(mm_pot) c = mm_pot.get_elastic_constants(si_bulk) E = youngs_modulus(c, cleavage_plane) nu = poisson_ratio(c, cleavage_plane, crack_direction) unit_slab = Diamond(directions=[crack_direction, cleavage_plane, crack_front], size=(1, 1, 1), symbol='Si', pbc=True, latticeconstant=5.431) unit_slab.positions[:, 1] += (unit_slab.positions[1, 1] - unit_slab.positions[0, 1]) / 2.0 unit_slab.set_scaled_positions(unit_slab.get_scaled_positions()) surface = unit_slab.copy() surface.center(vacuum, axis=1) surface.set_calculator(mm_pot)
""" Take ASE Diamond structure, input into PySCF and run """ import numpy as np import pyscf.pbc.gto as pbcgto import pyscf.pbc.dft as pbcdft from pyscf.pbc.tools import pyscf_ase import ase import ase.lattice from ase.lattice.cubic import Diamond ase_atom=Diamond(symbol='C', latticeconstant=3.5668) print(ase_atom.get_volume()) cell = pbcgto.Cell() cell.verbose = 5 cell.atom=pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.a=ase_atom.cell cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.build() mf=pbcdft.RKS(cell) mf.xc='lda,vwn' print(mf.kernel()) # [10,10,10]: -44.8811199336
def __init__(self, a0, nlayers, *args, **kwargs): self.atoms = Diamond(symbol="Sn", latticeconstant=a0, pbc=(1, 1, 1)) super().__init__()
def dia_111_pandey(sym, a0, nx=nx, ny=nx, nz=nz): """2x1 Pandey reconstructed (111) surface.""" sym = string2symbols(sym) if len(sym) == 1: a = Diamond(sym[0], size = [nx, ny, nz], latticeconstant = a0, directions=[ [1,-1,0], [1,1,-2], [1,1,1] ] ) else: a = B3(sym, size = [nx, ny, nz], latticeconstant = a0, directions=[ [1,-1,0], [1,1,-2], [1,1,1] ] ) sx, sy, sz = a.get_cell().diagonal() a.translate([sx/(12*nx), sy/(4*ny), sz/(6*nz)]) a.set_scaled_positions(a.get_scaled_positions()%1.0) bulk = a.copy() bondlen = a0*sqrt(3)/4 x, y, z = a.positions.T mask = np.abs(z-z.max()) < 0.1*a0 top1, top2 = np.arange(len(a))[mask].reshape(-1, 2).T mask = np.logical_and(np.abs(z-z.max()) < bondlen, np.logical_not(mask)) topA, topB = np.arange(len(a))[mask].reshape(-1, 2).T y[topA] += bondlen/3 y[topB] -= bondlen/3 y[top1] += bondlen x[top1] += a.cell[0,0]/(2*nx) x[top2] += a.cell[0,0]/(2*nx) mask = np.abs(z-z.min()) < 0.1*a0 bot1, bot2 = np.arange(len(a))[mask].reshape(-1, 2).T mask = np.logical_and(np.abs(z-z.min()) < bondlen, np.logical_not(mask)) botA, botB = np.arange(len(a))[mask].reshape(-1, 2).T y[botA] += bondlen/3 y[botB] -= bondlen/3 y[bot2] -= bondlen x[bot2] += a.cell[0,0]/(2*nx) x[bot1] += a.cell[0,0]/(2*nx) a.set_scaled_positions(a.get_scaled_positions()%1.0) return bulk, a
def setUp(self): self.pot = quippy.Potential('IP SW', param_str=""" <SW_params n_types="2" label="PRB_31_plus_H"> <comment> Stillinger and Weber, Phys. Rev. B 31 p 5262 (1984), extended for other elements </comment> <per_type_data type="1" atomic_num="1" /> <per_type_data type="2" atomic_num="14" /> <per_pair_data atnum_i="1" atnum_j="1" AA="0.0" BB="0.0" p="0" q="0" a="1.0" sigma="1.0" eps="0.0" /> <per_pair_data atnum_i="1" atnum_j="14" AA="8.581214" BB="0.0327827" p="4" q="0" a="1.25" sigma="2.537884" eps="2.1672" /> <per_pair_data atnum_i="14" atnum_j="14" AA="7.049556277" BB="0.6022245584" p="4" q="0" a="1.80" sigma="2.0951" eps="2.1675" /> <!-- triplet terms: atnum_c is the center atom, neighbours j and k --> <per_triplet_data atnum_c="1" atnum_j="1" atnum_k="1" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="1" atnum_j="1" atnum_k="14" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="1" atnum_j="14" atnum_k="14" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="14" atnum_j="1" atnum_k="1" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="14" atnum_j="1" atnum_k="14" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="14" atnum_j="14" atnum_k="14" lambda="21.0" gamma="1.20" eps="2.1675" /> </SW_params> """) self.fmax = 1e-4 self.at0 = Diamond('Si', latticeconstant=5.43) self.at0.set_calculator(self.pot) # relax initial positions and unit cell FIRE(StrainFilter(self.at0, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=self.fmax) self.C_ref = np.array([[ 151.4276439 , 76.57244456, 76.57244456, 0. , 0. , 0. ], [ 76.57244456, 151.4276439 , 76.57244456, 0. , 0. , 0. ], [ 76.57244456, 76.57244456, 151.4276439 , 0. , 0. , 0. ], [ 0. , 0. , 0. , 109.85498798, 0. , 0. ], [ 0. , 0. , 0. , 0. , 109.85498798, 0. ], [ 0. , 0. , 0. , 0. , 0. , 109.85498798]]) self.C_err_ref = np.array([[ 1.73091718, 1.63682097, 1.63682097, 0. , 0. , 0. ], [ 1.63682097, 1.73091718, 1.63682097, 0. , 0. , 0. ], [ 1.63682097, 1.63682097, 1.73091718, 0. , 0. , 0. ], [ 0. , 0. , 0. , 1.65751232, 0. , 0. ], [ 0. , 0. , 0. , 0. , 1.65751232, 0. ], [ 0. , 0. , 0. , 0. , 0. , 1.65751232]]) self.C_ref_relaxed = np.array([[ 151.28712587, 76.5394162 , 76.5394162 , 0. , 0. , 0. ], [ 76.5394162 , 151.28712587, 76.5394162 , 0. , 0. , 0. ], [ 76.5394162 , 76.5394162 , 151.28712587, 0. , 0. , 0. ], [ 0. , 0. , 0. , 56.32421772, 0. , 0. ], [ 0. , 0. , 0. , 0. , 56.32421772, 0. ], [ 0. , 0. , 0. , 0. , 0. , 56.32421772]]) self.C_err_ref_relaxed = np.array([[ 1.17748661, 1.33333615, 1.33333615, 0. , 0. , 0. ], [ 1.33333615, 1.17748661, 1.33333615, 0. , 0. , 0. ], [ 1.33333615, 1.33333615, 1.17748661, 0. , 0. , 0. ], [ 0. , 0. , 0. , 0.18959684, 0. , 0. ], [ 0. , 0. , 0. , 0. , 0.18959684, 0. ], [ 0. , 0. , 0. , 0. , 0. , 0.18959684]])
from mdcore import * from mdcore.tests import test_forces, test_virial # import ase_ext_io as io ### sx = 2 dx = 1e-6 dev_thres = 1e-4 ### tests = [ ( r6, dict(el1='Si', el2='Si', A=1.0, r0=1.0, cutoff=5.0), [ ( "dia-Si", Diamond("Si", size=[sx,sx,sx]) ) ] ), ( Brenner, Erhart_PRB_71_035211_SiC, [ ( "dia-C", Diamond("C", size=[sx,sx,sx]) ), ( "dia-Si", Diamond("Si", size=[sx,sx,sx]) ), ( "dia-Si-C", B3( [ "Si", "C" ], latticeconstant=4.3596, size=[sx,sx,sx]) ) ] ), ( BrennerScr, Erhart_PRB_71_035211_SiC__Scr, [ ( "dia-C", Diamond("C", size=[sx,sx,sx]) ), ( "dia-Si", Diamond("Si", size=[sx,sx,sx]) ), ( "dia-Si-C", B3( [ "Si", "C" ], latticeconstant=4.3596, size=[sx,sx,sx]) ) ] ), ( Brenner, Henriksson_PRB_79_114107_FeC, [ dict( name='dia-C', struct=Diamond('C', size=[sx,sx,sx]) ), dict( name='bcc-Fe', struct=BodyCenteredCubic('Fe', size=[sx,sx,sx]) ), dict( name='fcc-Fe',
""" Take ASE Diamond structure, input into PySCF and run """ import numpy as np import pyscf.pbc.gto as pbcgto import pyscf.pbc.dft as pbcdft from pyscf.pbc.tools import pyscf_ase import ase import ase.lattice from ase.lattice.cubic import Diamond ase_atom = Diamond(symbol='C', latticeconstant=3.5668) print(ase_atom.get_volume()) cell = pbcgto.Cell() cell.verbose = 5 cell.atom = pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.a = ase_atom.cell cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.build() mf = pbcdft.RKS(cell) mf.xc = 'lda,vwn' print(mf.kernel()) # [10,10,10]: -44.8811199336
E = youngs_modulus(C, params.cleavage_plane) print('Young\'s modulus %.1f GPa' % (E / units.GPa)) nu = poisson_ratio(C, params.cleavage_plane, params.crack_direction) print('Poisson ratio % .3f\n' % nu) # **** Setup crack slab unit cell ****** directions = [params.crack_direction, params.cleavage_plane, params.crack_front] print_crack_system(directions) # now, we build system aligned with requested crystallographic orientation unit_slab = Diamond(directions=directions, size=(1, 1, 1), symbol='Si', pbc=True, latticeconstant=a0) if (hasattr(params, 'check_rotated_elastic_constants') and # Check that elastic constants of the rotated system # lead to same Young's modulus and Poisson ratio params.check_rotated_elastic_constants): unit_slab.set_calculator(params.calc) C_r1 = measure_triclinic_elastic_constants(unit_slab, optimizer=FIRE, fmax=params.bulk_fmax) R = np.array([ np.array(x)/np.linalg.norm(x) for x in directions ])
import numpy as np import ase.io, sys # set of utility routines specific this this model/testing framework from utilities import relax_atoms, relax_atoms_cell # the current model import model a0 = 5.44 # initial guess at lattice constant, cell will be relaxed below fmax = 0.01 # maximum force following relaxtion [eV/A] if not hasattr(model, 'bulk_reference'): # set up the a bulk = Diamond(symbol='Si', latticeconstant=a0) # specify that we will use model.calculator to compute forces, energies and stresses bulk.set_calculator(model.calculator) # use one of the routines from utilities module to relax the initial # unit cell and atomic positions bulk = relax_atoms_cell(bulk, tol=fmax, traj_file=None) else: bulk = model.bulk_reference.copy() bulk.set_calculator(model.calculator) a0 = bulk.cell[0, 0] # get lattice constant from relaxed bulk print "got a0 ", a0 bulk = Diamond(symbol="Si", latticeconstant=a0,
def test_pbc(self): a = Diamond('Si', latticeconstant=5.432, size=[2,2,2]) sx, sy, sz = a.get_cell().diagonal() a.set_calculator(Tersoff()) e1 = a.get_potential_energy() a.set_pbc([True,True,False]) e2 = a.get_potential_energy() a.set_pbc(True) a.set_cell([sx,sy,2*sz]) e3 = a.get_potential_energy() self.assertEqual(e2, e3) # This should give the unrelaxed surface energy esurf = (e2-e1)/(2*sx*sy) * Jm2 self.assertTrue(abs(esurf-2.309) < 0.001)
class TestFitElasticConstants(matscipytest.MatSciPyTestCase): """ Tests of elastic constant calculation. We test with a cubic Silicon lattice, since this also has most of the symmetries of the lower-symmetry crystal families """ def setUp(self): self.pot = quippy.Potential('IP SW', param_str=""" <SW_params n_types="2" label="PRB_31_plus_H"> <comment> Stillinger and Weber, Phys. Rev. B 31 p 5262 (1984), extended for other elements </comment> <per_type_data type="1" atomic_num="1" /> <per_type_data type="2" atomic_num="14" /> <per_pair_data atnum_i="1" atnum_j="1" AA="0.0" BB="0.0" p="0" q="0" a="1.0" sigma="1.0" eps="0.0" /> <per_pair_data atnum_i="1" atnum_j="14" AA="8.581214" BB="0.0327827" p="4" q="0" a="1.25" sigma="2.537884" eps="2.1672" /> <per_pair_data atnum_i="14" atnum_j="14" AA="7.049556277" BB="0.6022245584" p="4" q="0" a="1.80" sigma="2.0951" eps="2.1675" /> <!-- triplet terms: atnum_c is the center atom, neighbours j and k --> <per_triplet_data atnum_c="1" atnum_j="1" atnum_k="1" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="1" atnum_j="1" atnum_k="14" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="1" atnum_j="14" atnum_k="14" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="14" atnum_j="1" atnum_k="1" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="14" atnum_j="1" atnum_k="14" lambda="21.0" gamma="1.20" eps="2.1675" /> <per_triplet_data atnum_c="14" atnum_j="14" atnum_k="14" lambda="21.0" gamma="1.20" eps="2.1675" /> </SW_params> """) self.fmax = 1e-4 self.at0 = Diamond('Si', latticeconstant=5.43) self.at0.set_calculator(self.pot) # relax initial positions and unit cell FIRE(StrainFilter(self.at0, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=self.fmax) self.C_ref = np.array([[ 151.4276439 , 76.57244456, 76.57244456, 0. , 0. , 0. ], [ 76.57244456, 151.4276439 , 76.57244456, 0. , 0. , 0. ], [ 76.57244456, 76.57244456, 151.4276439 , 0. , 0. , 0. ], [ 0. , 0. , 0. , 109.85498798, 0. , 0. ], [ 0. , 0. , 0. , 0. , 109.85498798, 0. ], [ 0. , 0. , 0. , 0. , 0. , 109.85498798]]) self.C_err_ref = np.array([[ 1.73091718, 1.63682097, 1.63682097, 0. , 0. , 0. ], [ 1.63682097, 1.73091718, 1.63682097, 0. , 0. , 0. ], [ 1.63682097, 1.63682097, 1.73091718, 0. , 0. , 0. ], [ 0. , 0. , 0. , 1.65751232, 0. , 0. ], [ 0. , 0. , 0. , 0. , 1.65751232, 0. ], [ 0. , 0. , 0. , 0. , 0. , 1.65751232]]) self.C_ref_relaxed = np.array([[ 151.28712587, 76.5394162 , 76.5394162 , 0. , 0. , 0. ], [ 76.5394162 , 151.28712587, 76.5394162 , 0. , 0. , 0. ], [ 76.5394162 , 76.5394162 , 151.28712587, 0. , 0. , 0. ], [ 0. , 0. , 0. , 56.32421772, 0. , 0. ], [ 0. , 0. , 0. , 0. , 56.32421772, 0. ], [ 0. , 0. , 0. , 0. , 0. , 56.32421772]]) self.C_err_ref_relaxed = np.array([[ 1.17748661, 1.33333615, 1.33333615, 0. , 0. , 0. ], [ 1.33333615, 1.17748661, 1.33333615, 0. , 0. , 0. ], [ 1.33333615, 1.33333615, 1.17748661, 0. , 0. , 0. ], [ 0. , 0. , 0. , 0.18959684, 0. , 0. ], [ 0. , 0. , 0. , 0. , 0.18959684, 0. ], [ 0. , 0. , 0. , 0. , 0. , 0.18959684]]) def test_measure_triclinic_unrelaxed(self): # compare to brute force method without relaxation C = measure_triclinic_elastic_constants(self.at0, delta=1e-2, optimizer=None) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref, tol=0.2) def test_measure_triclinic_relaxed(self): # compare to brute force method with relaxation C = measure_triclinic_elastic_constants(self.at0, delta=1e-2, optimizer=FIRE, fmax=self.fmax) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref_relaxed, tol=0.2) def testcubic_unrelaxed(self): C, C_err = fit_elastic_constants(self.at0, 'cubic', verbose=False, graphics=False) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref, tol=1e-2) if abs(C_err).max() > 0.: self.assertArrayAlmostEqual(C_err/units.GPa, self.C_err_ref, tol=1e-2) def testcubic_relaxed(self): C, C_err = fit_elastic_constants(self.at0, 'cubic', optimizer=FIRE, fmax=self.fmax, verbose=False, graphics=False) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref_relaxed, tol=1e-2) if abs(C_err).max() > 0.: self.assertArrayAlmostEqual(C_err/units.GPa, self.C_err_ref_relaxed, tol=1e-2) def testorthorhombic_unrelaxed(self): C, C_err = fit_elastic_constants(self.at0, 'orthorhombic', verbose=False, graphics=False) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref, tol=0.1) def testorthorhombic_relaxed(self): C, C_err = fit_elastic_constants(self.at0, 'orthorhombic', optimizer=FIRE, fmax=self.fmax, verbose=False, graphics=False) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref_relaxed, tol=0.1) def testmonoclinic_unrelaxed(self): C, C_err = fit_elastic_constants(self.at0, 'monoclinic', verbose=False, graphics=False) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref, tol=0.2) def testmonoclinic_relaxed(self): C, C_err = fit_elastic_constants(self.at0, 'monoclinic', optimizer=FIRE, fmax=self.fmax, verbose=False, graphics=False) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref_relaxed, tol=0.2) def testtriclinic_unrelaxed(self): C, C_err = fit_elastic_constants(self.at0, 'triclinic', verbose=False, graphics=False) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref, tol=0.2) def testtriclinic_relaxed(self): C, C_err = fit_elastic_constants(self.at0, 'triclinic', optimizer=FIRE, fmax=self.fmax, verbose=False, graphics=False) self.assertArrayAlmostEqual(C/units.GPa, self.C_ref_relaxed, tol=0.2)
def diamond_110_110(el, a0, n, crack_surface=[1,1,0], crack_front=[1,-1,0], skin_x=0.5, skin_y=1.0, central_x=-1.0, central_y=-1.0, vac=5.0): nx, ny, nz = n third_dir = np.cross(crack_surface, crack_front) a = Diamond(el, latticeconstant = a0, size = [nx, ny, nz], directions = [third_dir, crack_surface, crack_front] ) sx, sy, sz = a.get_cell().diagonal() a.translate([sx/(8*nx), sy/(4*ny), sz/(4*nz)]) a.set_scaled_positions(a.get_scaled_positions()) skin_x = skin_x*sx/nx skin_y = skin_y*sy/ny r = a.get_positions() g = np.where( np.logical_or( np.logical_or( np.logical_or( r[:, 0] < skin_x, r[:, 0] > sx-skin_x), r[:, 1] < skin_y), r[:, 1] > sy-skin_y), np.zeros(len(a), dtype=int), np.ones(len(a), dtype=int)) g = np.where( np.logical_or( np.logical_or( np.logical_or( r[:, 0] < sx/2-central_x, r[:, 0] > sx/2+central_x), r[:, 1] < sy/2-central_y), r[:, 1] > sy/2+central_y), g, 2*np.ones(len(a), dtype=int)) a.set_array('groups', g) a.set_cell([sx+2*vac, sy+2*vac, sz]) a.translate([vac, vac, 0.0]) a.set_pbc([False, False, True]) return a
def diamond_110_001(el, a0, n, crack_surface=[1,1,0], crack_front=[0,0,1], skin_x=1.0, skin_y=1.0, vac=5.0): nx, ny, nz = n third_dir = np.cross(crack_surface, crack_front) directions = [ third_dir, crack_surface, crack_front ] if np.linalg.det(directions) < 0: third_dir = -third_dir directions = [ third_dir, crack_surface, crack_front ] a = Diamond(el, latticeconstant = a0, size = [ nx,ny,nz ], directions = directions) sx, sy, sz = a.get_cell().diagonal() a.translate([a0/100,a0/100,a0/100]) a.set_scaled_positions(a.get_scaled_positions()) a.center() lx = skin_x*sx/nx ly = skin_y*sy/ny r = a.get_positions() g = np.where( np.logical_or( np.logical_or( np.logical_or( r[:, 0] < lx, r[:, 0] > sx-lx), r[:, 1] < ly), r[:, 1] > sy-ly), np.zeros(len(a), dtype=int), np.ones(len(a), dtype=int)) a.set_array('groups', g) a.set_cell([sx+2*vac, sy+2*vac, sz]) a.translate([vac, vac, 0.0]) a.set_pbc([False, False, True]) return a