Exemplo n.º 1
0
    def test_to_string(self):
        """
      Does generating a .cell file from the object work and is it consistent?
    """
        c1 = cell.Cell(open(self.cell1_path).read())
        c2 = cell.Cell(str(c1))

        self.assertEqual(str(c1), str(c2))
Exemplo n.º 2
0
    def test_lattice_abc(self):
        c = cell.Cell(open(self.cell2_path).read())

        lattice = [[6.0, 0.0, 0.0], [0.0, 6.0, 0.0], [0.0, 0.0, 6.0]]

        self.assertTrue(
            numpy.allclose(c.lattice, lattice, rtol=1e-05, atol=1e-08))
Exemplo n.º 3
0
  def test_al(self):
    """
      Read in ethanol cell and check contents.
    """

    for f in os.listdir(self.cells_path):
      print f

      path = os.path.join(self.cells_path, f)

      try:
        c = cell.Cell(open(path).read())
      except Exception, e:
        print type(e), e
Exemplo n.º 4
0
    def test_ethanol(self):
        """
      Read in ethanol cell and check contents.
    """
        c = cell.Cell(open(self.cell1_path).read())

        self.assertEqual(c.ions_type, 'POSITIONS_ABS')
        self.assertEqual(c.ions_units, 'ang')
        self.assertEqual(c.lattice_type, 'LATTICE_CART')
        self.assertEqual(c.lattice_units, 'ang')

        lattice = [[6.0, 0.0, 0.0], [0.0, 6.0, 0.0], [0.0, 0.0, 6.0]]

        self.assertTrue(
            numpy.allclose(c.lattice, lattice, rtol=1e-05, atol=1e-08))

        self.assertEqual(len(c.ions), 9)
        self.assertEqual(len(c.ions.species('H')), 6)
        self.assertEqual(len(c.ions.species('C')), 2)
        self.assertEqual(len(c.ions.species('O')), 1)

        C1 = c.ions.C1

        self.assertEqual(len(c.ions.within(C1, 1.5)), 4)
Exemplo n.º 5
0
 def test_lattice_wrong_shape(self):
     with self.assertRaises(cell.Cell.LatticeWrongShape):
         c = cell.Cell(open(self.cell3_path).read())
Exemplo n.º 6
0
import sys, os
import shutil
import random

import castepy.settings as settings
from castepy.input import cell
from castepy.calc import CastepCalc
from castepy.util import calc_from_path

psptest_path = os.path.join(settings.CASTEPY_ROOT, "templates/psptest")

merge_cell = cell.Cell(open(os.path.join(psptest_path, "psptest.cell")).read())

def make(source_ascpot, source_aeps, target_dir, **kwargs):
  cell = merge_cell

  s = os.path.split(source_ascpot)[1].split('_')[0]

  cell.ions[0].s = s

  target_name = s

  dir_ncp = os.path.join(target_dir, 'ncp/')
  dir_usp = os.path.join(target_dir, 'usp/')

  if not os.path.isdir(dir_ncp):
    os.mkdir(dir_ncp)
  if not os.path.isdir(dir_usp):
    os.mkdir(dir_usp)

  cell_target = os.path.join(dir_usp, "%s.cell" % target_name)
Exemplo n.º 7
0
def make(source,
         target_dir,
         target_name=None,
         num_cores=32,
         queue="parallel.q",
         xc_functional="pbe",
         cut_off_energy=50,
         ncp_pot=False,
         rel_pot=False,
         efg=False,
         c=None,
         **kwargs):

    source_dir, source_name = calc_from_path(source)
    calc = CastepCalc(source_dir, source_name)

    xc_functional = xc_functional.lower()

    if c is None:
        c = cell.Cell(calc.cell_file)

    c.other += merge_cell.other
    c.blocks.update(merge_cell.blocks)

    if ncp_pot:
        if xc_functional == 'pbe':
            _, required_files = pot.add_potentials(settings.NCP_PSPOT_PBE_DIR,
                                                   None, c, rel_pot)
        elif xc_functional == 'lda':
            _, required_files = pot.add_potentials(settings.NCP_PSPOT_LDA_DIR,
                                                   None, c, rel_pot)
        else:
            raise Exception("Cannot use XC functional %s with NCPs" %
                            xc_functional)

        pot.link_files(required_files, target_dir)
    else:
        print rel_pot
        pot.add_potentials_usp(c, rel_pot)

    if target_name is None:
        target_name = source_name

    cell_target = os.path.join(target_dir, "%s.cell" % target_name)
    param_target = os.path.join(target_dir, "%s.param" % target_name)
    sh_target = os.path.join(target_dir, "%s.sh" % target_name)

    sh_context = {
        'seedname': target_name,
        'num_cores': num_cores,
        'h_vmem': float(num_cores) / 8 * 23,
        'queue': queue,
        'CASTEPY_ROOT': settings.CASTEPY_ROOT,
        'USER_EMAIL': settings.USER_EMAIL,
    }

    sh_source = open(os.path.join(nmr_path, "nmr.sh")).read()
    sh_target_file = open(sh_target, "w+")
    param_target_file = open(param_target, "w+")

    params.xc_functional[0] = xc_functional
    params.cut_off_energy[0] = cut_off_energy

    if efg:
        params.magres_task = "efg"
    else:
        params.magres_task = "nmr"

    print >> sh_target_file, sh_source % sh_context
    print >> param_target_file, params

    cell_out = open(cell_target, "w+")

    print >> cell_out, c

    sh_target_file.close()
Exemplo n.º 8
0
import sys, os, argparse
import shutil
import random

import castepy.settings as settings
from castepy.input import cell, parameters, pot
from castepy.calc import CastepCalc
from castepy.util import calc_from_path

nmr_path = os.path.join(settings.CASTEPY_ROOT, "templates/nmr")

merge_cell = cell.Cell(open(os.path.join(nmr_path, "nmr.cell")).read())
params = parameters.Parameters(
    open(os.path.join(nmr_path, "nmr.param")).read())

import argparse

parser = argparse.ArgumentParser(
    description='Create a CASTEP NMR calculation.')

parser.add_argument('source',
                    help='A cell file to build the calculation from.')
parser.add_argument('target_dir',
                    help='A directory to build the calculation in.')
parser.add_argument('-n',
                    '--num_cores',
                    type=int,
                    help='Number of cores to use.',
                    default=32)
parser.add_argument('-q',
                    '--queue',