Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_c2d_input_format_npz_output_format_xyz(self):
"""c2d NaCl.npz NaCl.xyz"""
print(" RUN test_c2d_input_format_npz_output_format_xyz")
with tempfile.TemporaryDirectory() as tmpdir:
subprocess.run(
[ 'c2d', os.path.join(self.data_path,'NaCl.npz'), 'NaCl.xyz' ],
check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=tmpdir, env=self.myenv)
xyz = ase.io.read(os.path.join(tmpdir,'NaCl.xyz'))
self.assertEqual(len(xyz),len(self.ref_xyz))
self.assertTrue( ( xyz.symbols == self.ref_xyz.symbols ).all() )
self.assertTrue( ( xyz.get_initial_charges() ==
self.ref_xyz.get_initial_charges() ).all() )
self.assertTrue( ( xyz.cell == self.ref_xyz.cell ).all() )
def test_shrink_wrapped_direct_call(self):
a = io.read('aC.cfg')
r = a.positions
j, dr, i, abs_dr, shift = neighbour_list("jDidS", positions=r,
cutoff=1.85)
self.assertTrue((np.bincount(i) == np.bincount(j)).all())
dr_direct = r[j]-r[i]
abs_dr_from_dr = np.sqrt(np.sum(dr*dr, axis=1))
abs_dr_direct = np.sqrt(np.sum(dr_direct*dr_direct, axis=1))
self.assertTrue(np.all(np.abs(abs_dr-abs_dr_from_dr) < 1e-12))
self.assertTrue(np.all(np.abs(abs_dr-abs_dr_direct) < 1e-12))
self.assertTrue(np.all(np.abs(dr-dr_direct) < 1e-12))
import ase, ase.io
from seekpath import get_explicit_k_path
import seekpath.hpkot as hpkot
with_inv = True
ext_bravais = 'cP1'
# Get the POSCAR with the example structure
hpkot_folder = os.path.split(os.path.abspath(hpkot.__file__))[0]
folder = os.path.join(hpkot_folder,"band_path_data",ext_bravais)
poscar_with_inv = os.path.join(folder,'POSCAR_inversion')
poscar_no_inv = os.path.join(folder,'POSCAR_noinversion')
poscar = poscar_with_inv if with_inv else poscar_no_inv
asecell = ase.io.read(poscar)
system = (asecell.get_cell(), asecell.get_scaled_positions(),
asecell.get_atomic_numbers())
res = get_explicit_k_path(system, with_time_reversal=False)
for l, p in zip(res['explicit_kpoints_labels'], res['explicit_kpoints_abs']):
print "{}\t{}".format(l, p)
print res['explicit_kpoints_linearcoord']
for l, p in zip(res['explicit_kpoints_labels'], res['explicit_kpoints_linearcoord']):
print "{}\t{}".format(l, p)
print len(res['explicit_kpoints_labels']), len(res['explicit_kpoints_abs']), \
len(res['explicit_kpoints_linearcoord'])
def stub(self):
files=shell_exec("ls dirs").split('\n')
files=map(lambda x:x.replace('dir_',''),files)
fc2=readfc2('fc2')
for file in files:
from ase import io
ref=io.read('SPOSCAR')
a='dirs/dir_'+str(file)
atoms=io.read(a+"/POSCAR")
u=atoms.positions-ref.positions
f=-np.einsum('ijkl,jl',fc2,u)
forces=""
for force in f:
forces+=" %f %f %f \n"%tuple(force)
vasprun='\n'
vasprun+=forces
vasprun+='\n'
write(vasprun,a+"/vasprun.xml")
def force_constant(self,files):
"""
A wrapper method that simulates the behavior of the old
function ase.io.cif.read_cif by using the new generic ase.io.read
function.
Somewhere from 3.12 to 3.17 the tag concept was bundled with each Atom object. When
reading a CIF file, this is incremented and signifies the atomic species, even though
the CIF file do not have specific tags embedded. On reading CIF files we thus force the
ASE tag to zero for all Atom elements.
"""
from ase.io import read
# The read function returns a list as a cif file might contain multiple
# structures.
struct_list = read(fileobj, index=':', format='cif', **kwargs)
if index is None:
# If index is explicitely set to None, the list is returned as such.
for atoms_entry in struct_list:
atoms_entry.set_tags(0)
return struct_list
# Otherwise return the desired structure specified by index, if no index is specified,
# the last structure is assumed by default.
struct_list[index].set_tags(0)
return struct_list[index]
def read_band_structure(args, parser):
# Read first as Atoms object, then try as JSON band structure:
try:
atoms = read(args.calculation)
except UnknownFileTypeError:
pass
else:
return atoms2bandstructure(atoms, parser, args)
try:
bs = read_json(args.calculation)
except json.decoder.JSONDecodeError:
parser.error('File resembles neither atoms nor band structure')
objtype = getattr(bs, 'ase_objtype', None)
if objtype != 'bandstructure':
parser.error('Expected band structure, but this file contains a {}'
.format(objtype or type(bs)))
return bs
# creates: WL.png, Ni111slab2x2.png, WL_rot_c.png, WL_rot_a.png, WL_wrap.png, interface-h2o-wrap.png
import numpy as np
from ase.io import read, write
from ase.build import fcc111
exec(compile(open('WL.py').read(), 'WL.py', 'exec'))
# Use ase.io.read to load atoms object
W = read('WL.traj')
# View the water unit or print the unit cell size.
write('WL.png', W)
# We will need cellW later.
cellW = W.get_cell()
print(cellW)
# We will need as close a lattice match as possible. lets try this slab.
# Using the ase.build module, we make the fcc111 slab.
slab = fcc111('Ni', size=[2, 4, 3], a=3.55, orthogonal=True)
cell = slab.get_cell()
write('Ni111slab2x2.png', slab)
print(cell)
# Rotate the unit cell first to get the close lattice match with the slab.
W.set_cell([[cellW[1, 1], 0, 0],
[0, cellW[0, 0], 0],
def run(args, parser):
from ase.io.formats import UnknownFileTypeError
try:
atoms = read(args.name)
except UnknownFileTypeError:
# Probably a bandpath/bandstructure:
obj = read_json(args.name)
if isinstance(obj, BandPath):
path = obj
elif hasattr(obj, 'path'): # Probably band structure
path = obj.path
else:
parser.error('Strange object: {}'.format(obj))
else:
path = atoms2bandpath(atoms, path=args.path,
verbose=args.verbose,
k_points=args.k_points,
ibz_k_points=args.ibz_k_points)
plot_reciprocal_cell(path,
def lmp_structure(self):
write(self.POSCAR,"poscar_aces_structure")
atoms=io.read("poscar_aces_structure",format="vasp")
atoms=atoms.repeat([self.latx,self.laty,self.latz])
atoms.set_pbc([self.xp,self.yp,self.zp])
return atoms
"""
Demonstrates the use of the ASE library to load and create atomic
configurations that can be used in the dscribe package.
"""
import ase.io
from dscribe.descriptors import MBTR
from dscribe.descriptors import CoulombMatrix
from dscribe.descriptors import SineMatrix
from dscribe.utils import system_stats
# Load configuration from an XYZ file with ASE. See
# "https://wiki.fysik.dtu.dk/ase/ase/io/io.html" for a list of supported file
# formats.
atoms = ase.io.read("nacl.xyz")
atoms.set_cell([5.640200, 5.640200, 5.640200])
atoms.set_initial_charges(atoms.get_atomic_numbers())
# There are utilities for automatically detecting statistics for ASE Atoms
# objects. Typically some statistics are needed for the descriptors in order to
# e.g. define a proper zero-padding
stats = system_stats([atoms])
n_atoms_max = stats["n_atoms_max"]
atomic_numbers = stats["atomic_numbers"]
# Create descriptors for this system directly from the ASE atoms
cm = CoulombMatrix(n_atoms_max, permutation="sorted_l2").create(atoms)
sm = SineMatrix(n_atoms_max, permutation="sorted_l2").create(atoms)
mbtr = MBTR(
species=atomic_numbers,
k=[1, 2, 3],