def get_atoms(): srf = Atoms('Cu64', [(1.2763, 1.2763, 4.0000), (3.8290, 1.2763, 4.0000), (6.3816, 1.2763, 4.0000), (8.9343, 1.2763, 4.0000), (1.2763, 3.8290, 4.0000), (3.8290, 3.8290, 4.0000), (6.3816, 3.8290, 4.0000), (8.9343, 3.8290, 4.0000), (1.2763, 6.3816, 4.0000), (3.8290, 6.3816, 4.0000), (6.3816, 6.3816, 4.0000), (8.9343, 6.3816, 4.0000), (1.2763, 8.9343, 4.0000), (3.8290, 8.9343, 4.0000), (6.3816, 8.9343, 4.0000), (8.9343, 8.9343, 4.0000), (0.0000, 0.0000, 5.8050), (2.5527, 0.0000, 5.8050), (5.1053, 0.0000, 5.8050), (7.6580, 0.0000, 5.8050), (0.0000, 2.5527, 5.8050), (2.5527, 2.5527, 5.8050), (5.1053, 2.5527, 5.8050), (7.6580, 2.5527, 5.8050), (0.0000, 5.1053, 5.8050), (2.5527, 5.1053, 5.8050), (5.1053, 5.1053, 5.8050), (7.6580, 5.1053, 5.8050), (0.0000, 7.6580, 5.8050), (2.5527, 7.6580, 5.8050), (5.1053, 7.6580, 5.8050), (7.6580, 7.6580, 5.8050), (1.2409, 1.2409, 7.6081), (3.7731, 1.2803, 7.6603), (6.3219, 1.3241, 7.6442), (8.8935, 1.2669, 7.6189), (1.2803, 3.7731, 7.6603), (3.8188, 3.8188, 7.5870), (6.3457, 3.8718, 7.6649), (8.9174, 3.8340, 7.5976), (1.3241, 6.3219, 7.6442), (3.8718, 6.3457, 7.6649), (6.3945, 6.3945, 7.6495), (8.9576, 6.3976, 7.6213), (1.2669, 8.8935, 7.6189), (3.8340, 8.9174, 7.5976), (6.3976, 8.9576, 7.6213), (8.9367, 8.9367, 7.6539), (0.0582, 0.0582, 9.4227), (2.5965, -0.2051, 9.4199), (5.1282, 0.0663, 9.4037), (7.6808, -0.0157, 9.4235), (-0.2051, 2.5965, 9.4199), (2.1913, 2.1913, 9.6123), (5.0046, 2.5955, 9.4873), (7.5409, 2.5336, 9.4126), (0.0663, 5.1282, 9.4037), (2.5955, 5.0046, 9.4873), (5.3381, 5.3381, 9.6106), (7.8015, 5.0682, 9.4237), (-0.0157, 7.6808, 9.4235), (2.5336, 7.5409, 9.4126), (5.0682, 7.8015, 9.4237), (7.6155, 7.6155, 9.4317)]) c2 = Atoms('C2', [(3.2897, 3.2897, 10.6627), (4.2113, 4.2113, 10.6493)]) srf.extend(c2) srf.pbc = (1, 1, 0) srf.set_cell([10.2106, 10.2106, 20.6572], scale_atoms=False) mask = [a.index < 32 for a in srf] c1 = FixedPlane(-1, (1 / np.sqrt(2), 1 / np.sqrt(2), 1)) c2 = FixedPlane(-2, (1 / np.sqrt(2), 1 / np.sqrt(2), 1)) constraint = FixAtoms(mask=mask) srf.set_constraint([constraint, c1, c2]) return srf
def read_aims_output(filename, index=-1): """ Import FHI-aims output files with all data available, i.e. relaxations, MD information, force information etc etc etc. """ from ase_ext import Atoms, Atom from ase_ext.calculators.singlepoint import SinglePointCalculator from ase_ext.units import Ang, fs molecular_dynamics = False fd = open(filename, 'r') cell = [] images = [] n_periodic = -1 f = None pbc = False found_aims_calculator = False v_unit = Ang / (1000.0 * fs) while True: line = fd.readline() if not line: break if "List of parameters used to initialize the calculator:" in line: fd.readline() calc = read_aims_calculator(fd) calc.out = filename found_aims_calculator = True if "Number of atoms" in line: inp = line.split() n_atoms = int(inp[5]) if "| Unit cell:" in line: if not pbc: pbc = True for i in range(3): inp = fd.readline().split() cell.append([inp[1], inp[2], inp[3]]) if "Atomic structure:" in line and not molecular_dynamics: fd.readline() atoms = Atoms() for i in range(n_atoms): inp = fd.readline().split() atoms.append(Atom(inp[3], (inp[4], inp[5], inp[6]))) if "Complete information for previous time-step:" in line: molecular_dynamics = True if "Updated atomic structure:" in line and not molecular_dynamics: fd.readline() atoms = Atoms() velocities = [] for i in range(n_atoms): inp = fd.readline().split() atoms.append(Atom(inp[4], (inp[1], inp[2], inp[3]))) if molecular_dynamics: inp = fd.readline().split() if "Atomic structure (and velocities)" in line: fd.readline() atoms = Atoms() velocities = [] for i in range(n_atoms): inp = fd.readline().split() atoms.append(Atom(inp[4], (inp[1], inp[2], inp[3]))) inp = fd.readline().split() velocities += [[ float(inp[1]) * v_unit, float(inp[2]) * v_unit, float(inp[3]) * v_unit ]] atoms.set_velocities(velocities) images.append(atoms) if "Total atomic forces" in line: f = [] for i in range(n_atoms): inp = fd.readline().split() f.append([float(inp[2]), float(inp[3]), float(inp[4])]) if not found_aims_calculator: e = images[-1].get_potential_energy() images[-1].set_calculator( SinglePointCalculator(e, f, None, None, atoms)) e = None f = None if "Total energy corrected" in line: e = float(line.split()[5]) if pbc: atoms.set_cell(cell) atoms.pbc = True if not found_aims_calculator: atoms.set_calculator( SinglePointCalculator(e, None, None, None, atoms)) if not molecular_dynamics: images.append(atoms) e = None if found_aims_calculator: calc.set_results(images[-1]) images[-1].set_calculator(calc) fd.close() if molecular_dynamics: images = images[1:] # return requested images, code borrowed from ase_ext.io/trajectory.py if isinstance(index, int): return images[index] else: step = index.step or 1 if step > 0: start = index.start or 0 if start < 0: start += len(images) stop = index.stop or len(images) if stop < 0: stop += len(images) else: if index.start is None: start = len(images) - 1 else: start = index.start if start < 0: start += len(images) if index.stop is None: stop = -1 else: stop = index.stop if stop < 0: stop += len(images) return [images[i] for i in range(start, stop, step)]
from ase_ext import Atoms a = Atoms('H2', positions=[(0, 0, 0), (0, 0, 1.1)]) a.pbc[0] = 1 assert a.pbc.any() assert not a.pbc.all() a.pbc = 1 assert a.pbc.all() a.cell = (1, 2, 3) a.cell *= 2 a.cell[0, 0] = 3 assert not (a.cell.diagonal() - (3, 4, 6)).any()