import numpy as np
from osp.core.namespaces import QE
from osp.core.utils import pretty_print
from osp.wrappers.quantumespresso.qe_session import qeSession

# Creates simulation
sim = QE.Simulation()
k = QE.K_POINTS(vector6 = (7, 7, 7, 0, 0, 0), unit = "")

# Creates a cell, the element Silicon, a pseudopotential, two atoms and cell parameters
SiCell = QE.Cell()
Si = QE.Element(name = "Si")
SiPseudo = QE.PSEUDOPOTENTIAL(path = "Si.pbe-n-kjpaw_psl.1.0.0.UPF")
Si1 = QE.Atom()
celldm1 = QE.Celldm1(value = 5.43070, unit = "au")

# Adds pseudopotential and atoms to the element
# Describes element's mass
# Adds atoms and cell parameters to the cell
# Positions the atoms
Si.add(SiPseudo, Si1)
Si.add(QE.Mass(value = 28.085, unit = "amu"))
SiParams = QE.CellParams(tensor2 = [[0.5, 0.5, 0.],
                                      [0.5, 0., 0.5],
                                      [0., 0.5, 0.5]], unit = "")
SiCell.add(Si1, SiParams)
Si1.add(QE.Position(vector = (0, 0, 0), unit = ""))
SiCell.add(celldm1)

# Specifies the values of the cell parameters
O1 = O.add(QE.Atom())
O2 = O.add(QE.Atom())
O3 = O.add(QE.Atom())
Ba1 = Ba.add(QE.Atom())
Ti1 = Ti.add(QE.Atom())

O1.add(QE.Position(vector = [0.5, 0.5, 0.], unit = ""))
O2.add(QE.Position(vector = [0.5, 0., 0.5], unit = ""))
O3.add(QE.Position(vector = [0., 0.5, 0.5], unit = ""))
Ba1.add(QE.Position(vector = [0., 0., 0.], unit = ""))
Ti1.add(QE.Position(vector = [0.5, 0.5, 0.5], unit = ""))

cell.add(O1, O2, O3, Ba1, Ti1)

kpoints = QE.K_POINTS(vector6 = (4, 4, 4, 0, 0, 0), unit = "automatic")

sim.add(cell, O, Ba, Ti, kpoints)

paramdict = {
        'CONTROL': {
            'calculation': 'scf',
            'restart_mode': 'from_scratch',
            'wf_collect': '.true.',
        },
        'SYSTEM': {
            'ecutwfc': 30.,
            'ecutrho': 240.,
        },
        'ELECTRONS': {
            'conv_thr': 1.e-6,