How to use the ase.io function in ase

To help you get started, we’ve selected a few ase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SINGROUP / SOAPLite / tests / testGen.py View on Github external
lambda x: x*x*np.exp(-alphas[2]*x*x), # It can be as many basis functions as desired
       lambda x: x*x*np.exp(-alphas[3]*x*x), # but with minimum 2
       lambda x: x*x*np.exp(-alphas[4]*x*x)] # 
      );

#Define xyz structure
atoms = ase.io.read("Structs/au40cu40.xyz")

#Define positions
Hpos = np.genfromtxt('Structs/au40cu40H.dat') # Must be a list of a list

#Run soap calculations
x = soaplite.get_soap_locals_general(atoms, Hpos, rx, gss,  rCut=5.0, nMax=NMax, Lmax=2, all_atomtypes=[], eta=1.0)
np.savetxt("testme.txt",x)

atoms = ase.io.read("Structs/au40cu40.xyz")
Hpos=[[0,0,0]]
x = soaplite.get_soap_locals_general(atoms, Hpos, rx, gss,  rCut=5.0, nMax=NMax, Lmax=5, all_atomtypes=[], eta=1.0)
github SINGROUP / SOAPLite / tests / test_symmetry.py View on Github external
import ase
import numpy as np
from soaplite import genBasis
from numpy import genfromtxt
import time
from ase.structure import molecule
from ase.collections import g2
from scipy.spatial.distance import pdist
# GLOBALS

IS_PASS = True

#-------------- Define Structure ------------------------------------
#atoms = ase.Atoms('CH4', positions=[[-1.5, 0.0, 0.0],[ 1.5, 0.0, 0.0],[0.0, 1.5, 0.0],[ -1.5, 0.0, 0.0]])
#atoms = ase.io.read("../Structs/mos2_51.xyz")
atoms = ase.io.read("../Structs/au40cu40.xyz")

#-------------- Define Position of Local Environment ----------------
#Hpos = [[1.0,2.0,3.0],[4.0,5.0,6.0],[7.0,8.0,9.0],[10.0,11.0,12.0]]
#Hpos = genfromtxt('../Structs/mos2H.xyz').tolist()
Hpos = genfromtxt('../Structs/au40cu40H.dat').tolist()

#-------------- set Basis Function (rCut--soft, N_max) Environment ----------------
myAlphas, myBetas = genBasis.getBasisFunc(10.0, 5)
print("hello")


#-------------- run local chemical environments on each atom ----------------
features = soaplite.get_soap_structure(atoms, myAlphas, myBetas, rCut=10.0, NradBas=5, Lmax=9,crossOver=True) 
orig_atoms = atoms.copy()
# rotation check
for rotation in ['x', 'y', 'z']:
github libAtoms / matscipy / scripts / fracture_mechanics / quasistatic_crack.py View on Github external
###

# Atom types used for outputting the crack tip position.
ACTUAL_CRACK_TIP = 'Au'
FITTED_CRACK_TIP = 'Ag'

###

logger = screen

###

a, cryst, crk, k1g, tip_x0, tip_y0, bond1, bond2, boundary_mask, \
    boundary_mask_bulk, tip_mask = setup_crack(logger=logger)
ase.io.write('notch.xyz', a, format='extxyz')   

# Global parameters
basename = parameter('basename', 'quasistatic_crack')
calc = parameter('calc')
fmax = parameter('fmax', 0.01)

# Determine simulation control
k1_list = parameter('k1')
old_k1 = k1_list[0]
nsteps = len(k1_list)
tip_dx_list = parameter('tip_dx', np.zeros(nsteps))
tip_dy_list = parameter('tip_dy', np.zeros(nsteps))

# Run crack calculation.
tip_x = tip_x0
tip_y = tip_y0
github rosswhitfield / ase / ase / db / sqlite.py View on Github external
def encode(self, obj):
        return ase.io.jsonio.encode(obj)
github wolverton-research-group / qmpy / qmpy / io / __init__.py View on Github external
the returned Atoms object is then converted to a Structure.

    Examples::

        >>> io.read(INSTALL_PATH+'/io/files/POSCAR_FCC')
        >>> io.read(INSTALL_PATH+'/io/files/fe3o4.cif')

    """
    try:
        if 'cif' in source_file:
            return cif.read(source_file, *args, **kwargs)
        elif ( 'POSCAR' in source_file or
                'CONTCAR' in source_file ):
            return poscar.read(source_file, *args, **kwargs)
        else:
            return ase.io.read(source_file, *args, **kwargs)
    except:
        try:
            return poscar.read(source_file, *args, **kwargs)
        except Exception:
            pass
        try:
            return cif.read(source_file, *args, **kwargs)
        except Exception:
            pass
    raise FormatNotSupportedError('The file %s is in an unrecognized format\
            and cannot be read' % source_file)
github SUNCAT-Center / CatalysisHubBackend / api.py View on Github external
{systems(last: 10) {
              totalCount
              edges {
                node {
                  InputFile(format:"espresso-in")
                }
              }
            }}

        to generate QE input.

        """
        import ase.io
        import ase.io.formats
        supported_fileformats = [
                key for key, value in ase.io.formats.all_formats.items()
                if value[1].find('F') > 0
                ]
        if format in supported_fileformats:
            mem_file = StringIO.StringIO()
            mem_file.name = 'Export from http://catappdatabase.herokuapp.com/graphql'
            ase.io.write(mem_file, self._toatoms(), format)
            return mem_file.getvalue()
        else:
            return 'Unsupported format. Should be one of %s'\
                % str(supported_fileformats)
github rosswhitfield / ase / ase / optimize / activelearning / io.py View on Github external
def dump_experience(atoms, filename, restart):
    if restart is True:
        try:
            prev_atoms = io.read(filename, ':')  # Actively searching.
            if atoms not in prev_atoms:  # Avoid duplicates.
                parprint('Updating images (experiences) pool...')
                new_atoms = prev_atoms + [atoms]
                io.write(filename=filename, images=new_atoms)
        except Exception:
            io.write(filename=filename, images=atoms, append=True)
    if restart is False:
        io.write(filename=filename, images=atoms, append=False)
github libAtoms / matscipy / examples / fracture_mechanics / sinclair_crack / params.py View on Github external
regionII_III = cryst.arrays['groups'] == 0
    regionI = cryst.arrays['groups'] == 1

    regionII = regionI_II & regionII_III

    print(sum(regionI), sum(regionII), sum(regionIII))

    cryst.new_array('region', np.zeros(len(cryst), dtype=int))
    cryst.arrays['region'][regionI] = 1
    cryst.arrays['region'][regionII] = 2
    cryst.arrays['region'][regionIII] = 3

    del cryst.arrays['groups']
    cluster = cryst  # cluster and crystal only differ by PBC

ase.io.write('cryst.cfg', cryst)
ase.io.write('cluster.cfg', cluster)
github libAtoms / matscipy / scripts / fracture_mechanics / plot_two_bonds.py View on Github external
plt.xlabel(r'Crack position / $\mathrm{\AA}$')
plt.ylabel(r'Potential energy / eV')
plt.legend(loc='upper right')
#plt.ylim(-0.05, 0.30)
plt.draw()


plt.figure(2)
#plt.clf()

bond_length, gamma = np.loadtxt('../cohesive-stress/gamma_bond_length.out', unpack=True)

s = bond_length - bond_length[0]
s1 = bond_lengths1 - bond_length[0]

surface = ase.io.read('../cohesive-stress/surface.xyz')
area = surface.cell[0,0]*surface.cell[2,2]
gamma_sp = splrep(bond_length, gamma)
E_surf = splev(bond_lengths1, gamma_sp)*area

plt.plot(s1, (epot1 - E0_1), '-', label='total energy')
plt.plot(s, E_surf, '-', label=r'surface energy')
plt.plot(s1, (epot1 - E0_1 - E_surf), '--', label='elastic energy')
#plt.xlim(2.35, 4.5)

plt.axhline(0, color='k')

plt.xlabel(r'Bond extension $s$ / $\mathrm{\AA}$')
plt.ylabel(r'Energy / eV/cell')
plt.legend(loc='upper right')
plt.draw()
github rosswhitfield / ase / ase / optimize / minimahopping.py View on Github external
def _plot_qn(self, index, line):
        """Plots a dashed vertical line for the optimization."""
        if line[1] == 'performing MD':
            return
        file = os.path.join(self._rundirectory, 'qn%05i.traj' % index)
        if os.path.getsize(file) == 0:
            return
        traj = io.Trajectory(file, 'r')
        energies = [traj[0].get_potential_energy(),
                    traj[-1].get_potential_energy()]
        if index > 0:
            file = os.path.join(self._rundirectory, 'md%05i.traj' % index)
            atoms = io.read(file, index=-3)
            energies[0] = atoms.get_potential_energy()
        self._ax.plot([index + 0.25] * 2, energies, ':k')