# Copyright 2014-2018 The PySCF Developers. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import unittest
from pyscf.nao.m_siesta_utils import get_siesta_command, get_pseudo

class KnowValues(unittest.TestCase):
  
  def test_siesta2sv_df(self):
    import subprocess
    import os

    siesta_fdf = """
    xml.write                  .true.
    PAO.EnergyShift            100 meV
    %block ChemicalSpeciesLabel
     1  11  Na
    %endblock ChemicalSpeciesLabel
    
    NumberOfAtoms       2
    NumberOfSpecies     1
    %block AtomicCoordinatesAndAtomicSpecies
        0.77573521    0.00000000    0.00000000   1
       -0.77573521    0.00000000    0.00000000   1
    %endblock AtomicCoordinatesAndAtomicSpecies
    
    MD.NumCGsteps              0
    COOP.Write                 .true.
    WriteDenchar               .true.
    """
    label = 'siesta'
    fi = open(label+'.fdf', 'w')
    print(siesta_fdf, file=fi)
    fi.close()
    for sp in ['Na']: 
      try:
        os.remove(sp+'.psf')
      except :
        pass
      try:
        pppath = get_pseudo(sp)
      except:
        print('get_pseudo( '+sp+' ) is not working--> skip siesta run' )
        return
      os.symlink(pppath, sp+'.psf')
    errorcode = subprocess.call(get_siesta_command(label), shell=True)
    if errorcode: raise RuntimeError('siesta returned an error: {0}'.format(errorcode))

    # run test system_vars
    from pyscf.nao import mf
    sv  = mf(label=label)
    self.assertEqual(sv.norbs, 10)
    self.assertTrue( sv.diag_check() )
    self.assertTrue( sv.overlap_check())

if __name__ == "__main__": unittest.main()

[((68, 27, 68, 42), 'unittest.main', 'unittest.main', ({}, {}), '()', False, 'import unittest\n'), ((63, 10, 63, 25), 'pyscf.nao.mf', 'mf', (), '', False, 'from pyscf.nao import mf\n'), ((57, 6, 57, 35), 'os.symlink', 'os.symlink', ({(57, 17, 57, 23): 'pppath', (57, 25, 57, 34): "(sp + '.psf')"}, {}), "(pppath, sp + '.psf')", False, 'import os\n'), ((58, 32, 58, 57), 'pyscf.nao.m_siesta_utils.get_siesta_command', 'get_siesta_command', ({(58, 51, 58, 56): 'label'}, {}), '(label)', False, 'from pyscf.nao.m_siesta_utils import get_siesta_command, get_pseudo\n'), ((49, 8, 49, 28), 'os.remove', 'os.remove', ({(49, 18, 49, 27): "(sp + '.psf')"}, {}), "(sp + '.psf')", False, 'import os\n'), ((53, 17, 53, 31), 'pyscf.nao.m_siesta_utils.get_pseudo', 'get_pseudo', ({(53, 28, 53, 30): 'sp'}, {}), '(sp)', False, 'from pyscf.nao.m_siesta_utils import get_siesta_command, get_pseudo\n')]