diff --git a/pyscf/gto/mole.py b/pyscf/gto/mole.py index 3d8a476c45..76f5e8b95b 100644 --- a/pyscf/gto/mole.py +++ b/pyscf/gto/mole.py @@ -2577,11 +2577,16 @@ def build(self, dump_input=True, parse_arg=ARGPARSE, # number of electrons are consistent. self.nelec - if self.magmom is None or len(self.magmom) != self.natm: + if self.magmom is None: + self.magmom = [0,] * self.natm + elif len(self.magmom) != self.natm: + logger.warn(self, 'len(magmom) != natm. Set magmom to zero') self.magmom = [0,] * self.natm if self.spin == 0 and abs(numpy.sum(self.magmom) - self.spin) > 1e-6: #don't check for unrestricted calcs. raise ValueError("mol.magmom is set incorrectly.") + if isinstance(self.magmom, np.ndarray): + self.magmom = self.magmom.tolist() if self.symmetry: self._build_symmetry() diff --git a/pyscf/pbc/gto/cell.py b/pyscf/pbc/gto/cell.py index 49bc31f257..87282fbfd4 100644 --- a/pyscf/pbc/gto/cell.py +++ b/pyscf/pbc/gto/cell.py @@ -99,7 +99,8 @@ def dumps(cell): celldic['pseudo'] = repr(cell.pseudo) celldic['ecp'] = repr(cell.ecp) # Explicitly convert mesh because it is often created as numpy array - celldic['mesh'] = list(cell.mesh) + if isinstance(cell.mesh, np.ndarray): + celldic['mesh'] = cell.mesh.tolist() try: return json.dumps(celldic) diff --git a/pyscf/pbc/gto/test/test_cell.py b/pyscf/pbc/gto/test/test_cell.py index c035d271dc..5dee058140 100644 --- a/pyscf/pbc/gto/test/test_cell.py +++ b/pyscf/pbc/gto/test/test_cell.py @@ -84,6 +84,10 @@ def test_mixed_basis(self): def test_dumps_loads(self): cl1.loads(cl1.dumps()) + # see issue 2026 + from pyscf.pbc.tools.pbc import super_cell + sc = super_cell(cl1, [1,1,1]) + sc.dumps() def test_get_lattice_Ls(self): #self.assertEqual(cl1.get_lattice_Ls([0,0,0]).shape, (1 , 3)) diff --git a/pyscf/pbc/tools/pbc.py b/pyscf/pbc/tools/pbc.py index 77042a5e3a..7ca867fd21 100644 --- a/pyscf/pbc/tools/pbc.py +++ b/pyscf/pbc/tools/pbc.py @@ -590,7 +590,10 @@ def super_cell(cell, ncopy, wrap_around=False): supcell.a = np.einsum('i,ij->ij', ncopy, a) mesh = np.asarray(ncopy) * np.asarray(cell.mesh) supcell.mesh = (mesh // 2) * 2 + 1 - supcell.magmom = list(cell.magmom) * np.prod(ncopy) + if isinstance(cell.magmom, np.ndarray): + supcell.magmom = cell.magmom.tolist() * np.prod(ncopy) + else: + supcell.magmom = cell.magmom * np.prod(ncopy) return _build_supcell_(supcell, cell, Ls)