def _initialize_lammps(self, structure): lmp = lammps.Lammps(units='metal', style='full', args=['-log', 'none', '-screen', 'none']) lmp.system.add_pymatgen_structure(structure, self.elements) lmp.thermo.add('my_ke', 'ke', 'all') return lmp
def initiate_lmp(self, cs_springs): """ Initialises the system for the structure (read in from a lammps input file) with non-changing parameters implemented. Args: cs_springs (dict): The key is the atom label (str) and the value the spring values (list(float)). Returns: lmp (obj): Lammps system object with structure and specified commands implemented. """ lmp = lammps.Lammps(units='metal', style='full', args=['-log', 'none', '-screen', 'none']) lmp.command('read_data {}'.format(self.file_name)) lmp.command('group cores type {}'.format(self.type_core())) if len(self.bond_types) != 0: lmp.command('group shells type {}'.format(self.type_shell())) if cs_springs: lmp.command('pair_style buck/coul/long/cs 10.0') lmp.command('pair_coeff * * 0 1 0') lmp.command('bond_style harmonic') for bond in self.bond_types: lmp.command(bond.bond_string()) else: lmp.command('pair_style buck/coul/long 10.0') lmp.command('pair_coeff * * 0 1 0') lmp.command('kspace_style ewald 1e-6') #setup for minimization lmp.command('min_style cg') return lmp
async def submit(self, structure, potential, properties=None, lammps_additional_commands=None): properties = properties or {'stress', 'energy', 'forces'} results = {} lammps_additional_commands = lammps_additional_commands or ['run 0'] lmp = lammps.Lammps(units='metal', style='full', args=['-log', 'none', '-screen', 'none']) elements, rotation_matrix = lmp.system.add_pymatgen_structure( structure) inv_rotation_matrix = np.linalg.inv(rotation_matrix) lmp.thermo.add('my_ke', 'ke', 'all') if 'initial_positions' in properties: results['initial_positions'] = np.dot(lmp.system.positions.copy(), inv_rotation_matrix) lammps_files = write_potential_files(potential, elements=elements, unique_id=self.unique_id) for filename, content in lammps_files.items(): with open(filename, 'w') as f: f.write(content) lammps_commands = write_potential(potential, elements=elements, unique_id=self.unique_id) for command in lammps_commands: lmp.command(command) for command in lammps_additional_commands: lmp.command(command) # to handle non-orthogonal unit cells if 'lattice' in properties: lengths, angles_r = lmp.box.lengths_angles angles = [math.degrees(_) for _ in angles_r] results['lattice'] = pmg.Lattice.from_parameters( *lengths, *angles).matrix if 'positions' in properties: results['positions'] = np.dot(lmp.system.positions.copy(), inv_rotation_matrix) if 'stress' in properties: S = lmp.thermo.computes['thermo_press'].vector results['stress'] = np.array([[S[0], S[3], S[5]], [S[3], S[1], S[4]], [S[5], S[4], S[2]]]) if 'energy' in properties: results['energy'] = lmp.thermo.computes[ 'thermo_pe'].scalar + lmp.thermo.computes['my_ke'].scalar if 'forces' in properties: results['forces'] = lmp.system.forces.copy() if 'symbols' in properties: results['symbols'] = [elements[i - 1] for i in lmp.system.types[0]] if 'velocities' in properties: results['velocities'] = np.dot(lmp.system.velocities.copy(), inv_rotation_matrix) if 'timesteps' in properties: results['timesteps'] = lmp.time_step # compatibility... future = asyncio.Future() future.set_result({'results': results}) return future