1#!/usr/bin/env python
2
3'''
4Convert back and forth between the molecule (open boundary) and the 0D PBC
5system.
6'''
7
8import numpy
9from pyscf import gto, scf
10from pyscf.pbc import gto as pbcgto
11from pyscf.pbc import scf as pbcscf
12from pyscf.pbc import df
13
14cell = pbcgto.Cell()
15cell.atom = 'N 0 0 0; N 0 0 1.2'
16cell.basis = 'gth-dzvp'
17cell.pseudo = 'gth-pade'
18cell.a = numpy.eye(3)
19cell.dimension = 0
20cell.symmetry = True
21cell.build()
22
23mf = pbcscf.RHF(cell)
24mf.with_df = df.AFTDF(cell)
25mf.run()
26print('E(HF) with 0D PBC RHF calculation %s' % mf.e_tot)
27
28#
29# Convert cell to mol.
30#
31# Except lattice vectors, the mole object inherits all parameters from the
32# cell object, like geometry, basis sets, and pseudopotential.  Using the
33# generated mol object with molecular code, it should produce the same results
34# as the 0D PBC calculation
35#
36mol = cell.to_mol()
37mf = scf.RHF(mol).run()
38print('E(HF) with molecular RHF calculation %s' % mf.e_tot)
39
40# Cell and Mole have almost the same structure. If cell was fed to the
41# molecular functions, the code is able to handle the cell without any
42# errors. However, due to the different treatments of nuclear repulsion
43# energy, a small discrepancy will be found in the total energy.
44mf = scf.RHF(cell).run()
45print('E(HF) of molecular RHF with cell %s' % mf.e_tot)
46
47#
48# Convert mol back to cell.
49#
50# The mol ojbect above contains all information of the pbc system which was
51# initialized at the beginning. Using the "view" method to convert mol back to
52# the cell object, all information can be transfer to the resultant cell
53# object. Lattice vectors "a" are not available in the mole object. It needs
54# to be specified in the cell.
55#
56cell_0D = mol.view(pbcgto.Cell)
57cell_0D.a = numpy.eye(3)
58cell_0D.dimension = 0
59mf = pbcscf.RHF(cell).density_fit().run()
60print('E(HF) with 0D PBC RHF calculation %s' % mf.e_tot)
61