def structure2quippy(structure, anonymize=False, scale=False, standardize=False, primitivize=False, symprec=1e-3, from_dict=False): ''' Convert pymatgen Structure to quippy Atoms Args: structure (pymatgen.core.Structure): pymatgen Structure object anonymize (bool): replace all species with hydrogen scale (bool): scale volume to 1 Å^3 / atom standardize (bool): use spglib to standardize the structure primitivize (bool): use spglib to standardize and primitivize the structure symprec (float): symmetry tolerance factor (see spglib documentation) Returns: quippy.atoms.Atoms: quippy Atoms object ''' if from_dict: structure = Structure.from_dict(structure) cell = structure2cell(structure, anonymize) # (matrix, positions, numbers) if standardize or primitivize: cell = standardize_cell(cell, to_primitive=primitivize, symprec=symprec) if cell: cell = list(cell) else: try: # spglib can't make a primitive return ase2qp(AseAtomsAdaptor.get_atoms(structure)) except ValueError as ve: # TODO: warn the user here maybe return None # Must be either really f****d up or disordered if scale: cell = list(cell) # cell[0] = matrix volume = np.dot(np.cross(cell[0][0], cell[0][1]), cell[0][2]) # len(cell[2]) = n_atoms cell[0] = cell[0] / np.cbrt(volume / len(cell[2])) return ase2qp( Atoms(cell=cell[0], positions=cell[1], numbers=list(cell[2]), pbc=True))
def get(self): parser = flask_restful.reqparse.RequestParser() argument_names = [ 'atoms', 'spkitMax', 'nocenters', 'gaussian_width', 'spkit', 'cutoff', 'cutoff_transition_width', 'nmax', 'lmax' ] for argument_name in argument_names: parser.add_argument(ARGUMENTS[argument_name]) args = parser.parse_args(strict=True) args['atoms'] = atoms_utils.loads(args['atoms']) args['atoms'] = ase2qp(args['atoms']) args['spkitMax'] = json.loads(args['spkitMax']) if not args['spkit']: args['spkit'] = get_spkit(args['atoms']) # args['atoms'] = [args['atoms']] soaps = get_soap(**args) # soaps = {key: value.tolist() for key, value in soaps.iteritems()} soaps = soaps.tolist() return flask.jsonify(soaps)
def get(self): parser = flask_restful.reqparse.RequestParser() argument_names = [ 'atoms', 'nocenters', 'chem_channels', 'centerweight', 'gaussian_width', 'spkitMax', 'chemicalProjection', 'is_fast_average', 'cutoff', 'cutoff_transition_width', 'nmax', 'lmax' ] for argument_name in argument_names: parser.add_argument(ARGUMENTS[argument_name]) args = parser.parse_args(strict=True) if args['spkitMax']: args['spkitMax'] = json.loads(args['spkitMax']) args['atoms'] = json.loads(args['atoms']) args['atoms'] = [atoms_utils.loads(atoms) for atoms in args['atoms']] args['atoms'] = [ase2qp(atoms) for atoms in args['atoms']] soaps = get_Soaps(**args) soaps = [{key: value.tolist() for key, value in soap.iteritems()} for soap in soaps] return flask.jsonify(soaps)
def get_quippy_atoms(self): ase_atoms = self.inputs.anonymous_aiida_structure.get_ase() quippy_atoms = ase2qp(ase_atoms) self.ctx.quippy_atoms = quippy_atoms
import sys sys.path.insert(0, '/home/app/glosim2') from ase import Atoms import numpy as np from libmatch.soap import get_Soaps from libmatch.utils import ase2qp # Read structures and convert to ase Atoms # raw_structures = # ase_atoms = quippy_atoms = [ase2qp(ase_atoms_instance) for ase_atoms_instance in ase_atoms] # atoms: [quippy.Atoms] # nocenters: None or [Atomic numbers to ignore] # chem_channels: bool (whether or not to include chemical combinations) # centerweight: float (weight of gaussian on central atom) # gaussian_width: float (sigma of gaussian) # cutoff: float (integration cutoff distance) # cutoff_transition_width: float (width of sigmoid used to smooth integration cutoff) # nmax: int (number of radial basis functions) # lmax: int (number of spherical harmonics) # spkitMax: dict {atomic numbers: max. number of occurrences in a structure in the set atoms} # nprocess: int (number of subprocesses spawned) # chemicalProjection: ??? # dispbar: bool ??? # is_fast_average: None or bool (use fast averaging to calculate average soap; no average calculated if None) soaps = get_Soaps(atoms=quippy_atoms, nocenters=None, chem_channels=False, centerweight=1.0,