def test_to_from_dict(self): d = self.nwi.as_dict() nwi = NwInput.from_dict(d) self.assertIsInstance(nwi, NwInput) #Ensure it is json-serializable. json.dumps(d) d = self.nwi_symm.as_dict() nwi_symm = NwInput.from_dict(d) self.assertIsInstance(nwi_symm, NwInput) json.dumps(d)
def test_to_from_dict(self): d = self.nwi.as_dict() nwi = NwInput.from_dict(d) self.assertIsInstance(nwi, NwInput) # Ensure it is json-serializable. json.dumps(d) d = self.nwi_symm.as_dict() nwi_symm = NwInput.from_dict(d) self.assertIsInstance(nwi_symm, NwInput) json.dumps(d)
def _prepare_pymatgen_dict(parameters,struct=None): from pymatgen.io.nwchem import NwInput import copy par = copy.deepcopy(parameters) add_cell = par.pop('add_cell',False) if struct: if add_cell: par['geometry_options'].append( '\n system crystal\n' ' lat_a {}\n lat_b {}\n lat_c {}\n' ' alpha {}\n beta {}\n gamma {}\n' ' end'.format(*(struct.cell_lengths+struct.cell_angles))) if 'mol' not in par: par['mol'] = {} if 'sites' not in par['mol']: par['mol']['sites'] = [] atoms = struct.get_ase() for i,atom_type in enumerate(atoms.get_chemical_symbols()): xyz = [] if add_cell: xyz = atoms.get_scaled_positions()[i] else: xyz = atoms.get_positions()[i] par['mol']['sites'].append({ 'species': [ { 'element': atom_type, 'occu': 1 } ], 'xyz': xyz }) return str(NwInput.from_dict(par))