示例#1
0
def multiplicity(position, sgname=None, sgno=None, cell_choice='standard'):
    """
    Calculates the multiplicity of a fractional position in the unit cell.
    If called by sgno, cell_choice is necessary for eg rhombohedral space groups.

    """

    if sgname != None:
        mysg = sg.sg(sgname=sgname, cell_choice=cell_choice)
    elif sgno != None:
        mysg = sg.sg(sgno=sgno, cell_choice=cell_choice)
    else:
        raise ValueError('No space group information provided')

    lp = n.zeros((mysg.nsymop, 3))

    for i in range(mysg.nsymop):
        lp[i, :] = n.dot(position, mysg.rot[i]) + mysg.trans[i]

    lpu = n.array([lp[0, :]])
    multi = 1

    for i in range(1, mysg.nsymop):
        for j in range(multi):
            t = lp[i] - lpu[j]
            if n.sum(n.mod(t, 1)) < 0.00001:
                break
            else:
                if j == multi - 1:
                    lpu = n.concatenate((lpu, [lp[i, :]]))
                    multi += 1
    return multi
示例#2
0
def open_cif(param, phase):
    """
	Open a cif file a build a structure for phase number "phase"
	filename: param['structure_phase_%i' %phase]
	
	returns 
	- a structure with cif information
	
	sets
	- param['sgno_phase_%i' %phase] : space group number
	- param['sgname_phase_%i' %phase] : space group name
	- param['cell_choice_phase_%i' %phase] : not 100% sure
	- param['unit_cell_phase_%i' %phase] : unit cell parameters as [a,b,c,alpha,beta,gamma']
	
	Adapted from polyxsim.structure
	Created: 12/2019, S. Merkel, Univ. Lille, France
	"""
    file = param['structure_phase_%i' % phase]
    cf = ReadCif(
        file
    )  # Generate an error if reading cif fails which is not always true below
    struct = structure.build_atomlist()
    struct.CIFread(ciffile=file)
    param['sgno_phase_%i' % phase] = sg.sg(sgname=struct.atomlist.sgname).no
    param['sgname_phase_%i' % phase] = struct.atomlist.sgname
    param['cell_choice_phase_%i' %
          phase] = sg.sg(sgname=struct.atomlist.sgname).cell_choice
    param['unit_cell_phase_%i' % phase] = struct.atomlist.cell
    return struct
示例#3
0
def generate_grains(param):
# If pick out grain for phase
    if param['gen_phase'][0] != 0:
		#Making random list of grain numbers
        rand_grain_order = n.argsort(n.random.randn(param['no_grains']))

        no_picked_grains = 0
        for i in range(param['no_phases']):
            phase = param['gen_phase'][i*2+1]
            no_grains_phase = int(param['gen_phase'][i*2+2])
            param['no_grains_phase_%i' %phase] = no_grains_phase
            param['grain_list_phase_%i' %phase] = \
                n.array(param['grain_list'])[rand_grain_order[no_picked_grains:no_picked_grains+no_grains_phase]]
            no_picked_grains += no_grains_phase
            for grain in param['grain_list_phase_%i' %phase]:
                param['phase_grains_%i' %grain] = phase
    param['gen_phase'][0] = 0  # Done

# Generate U if gen_U on
    if param['gen_U'] != 0: 
        for phase in param['phase_list']:        
            U = generate_U(param['no_grains_phase_%i' %phase],sgi = sg.sg(sgname=param['sgname_phase_%i' %phase]))
            for i in range(param['no_grains_phase_%i' %phase]):
                param['U_grains_%s' %(param['grain_list_phase_%i' %phase][i])] = U[i]
        param['gen_U'] = 0
        
# Generate pos if gen_pos on
    if param['gen_pos'][0] != 0: 
        pos = generate_pos(param['no_grains'],param['gen_pos'][1],sample_xyz=param['sample_xyz'],sample_cyl=param['sample_cyl'])
        for i in range(param['no_grains']):
            param['pos_grains_%s' %(param['grain_list'][i])] = pos[i]
        param['gen_pos'][0] = 0
	
# Generate eps if gen_eps on
    for phase in param['phase_list']:
        if param['gen_eps_phase_%i' %phase][0] != 0: 
            eps = generate_eps(param['no_grains_phase_%i' %phase],param['gen_eps_phase_%i' %phase][1:5])
            for i in range(param['no_grains_phase_%i' %phase]):
                param['eps_grains_%s' %(param['grain_list_phase_%i' %phase][i])] = eps[i]
            param['gen_eps_phase_%i' %phase][0] = 0
    if 'gen_eps' in param:
        del param['gen_eps']


# Generate size if gen_size on
    for phase in param['phase_list']:
        if param['gen_size_phase_%i' %phase][0] != 0: 
            size = grain_size(param['no_grains_phase_%i' %phase],
                              param['gen_size_phase_%i' %phase][1],
                              param['gen_size_phase_%i' %phase][2:4],
                              param['sample_vol']*param['vol_frac_phase_%i' %phase])
            for i in range(param['no_grains_phase_%i' %phase]):
                param['size_grains_%s' %(param['grain_list_phase_%i' %phase][i])] = size[i]
                param['gen_size_phase_%i' %phase][0] = 0
    if 'gen_size' in param:
        del param['gen_size']
示例#4
0
def open_structure(param, phase):
    file = param['structure_phase_%i' % phase]
    if file[-3:] == 'cif':
        if ('structure_datablock_phase_%i' % phase) in param:
            datablock = param['structure_datablock_phase_%i' % phase]
        else:
            datablock = None
        struct = structure.build_atomlist()
        struct.CIFread(ciffile=file, cifblkname=datablock)
    elif file[-3:] == 'pdb':
        struct = structure.build_atomlist()
        struct.PDBread(pdbfile=file)
    else:
        raise IOError('Unknown structure file format')
    param['sgno_phase_%i' % phase] = sg.sg(sgname=struct.atomlist.sgname).no
    param['sgname_phase_%i' % phase] = struct.atomlist.sgname
    param['cell_choice_phase_%i' %
          phase] = sg.sg(sgname=struct.atomlist.sgname).cell_choice
    param['unit_cell_phase_%i' % phase] = struct.atomlist.cell
    return struct
示例#5
0
def StructureFactor(hkl, ucell, sgname, atoms, disper=None):
    """
    Calculation of the structure factor of reflection hkl
    
    [Freal Fimg] = StructureFactor(hkl,unit_cell,sg,atoms)
    
    INPUT : hkl =       [h, k, l] 
            unit_cell = [a, b, c, alpha, beta, gamma] 
            sgname:     space group name (e.g. 'P 21/c')
            atoms:      structural parameters (as an object)
    OUTPUT: The real and imaginary parts of the the structure factor
    
    Henning Osholm Sorensen, June 23, 2006.
    Translated to python code April 8, 2008
    """
    mysg = sg.sg(sgname=sgname)
    stl = tools.sintl(ucell, hkl)
    noatoms = len(atoms)

    Freal = 0.0
    Fimg = 0.0

    for i in range(noatoms):
        #Check whether isotrop or anisotropic displacements
        if atoms[i].adp_type == 'Uiso':
            U = atoms[i].adp
            expij = n.exp(-8 * n.pi**2 * U * stl**2)
        elif atoms[i].adp_type == 'Uani':
            # transform Uij to betaij
            betaij = Uij2betaij(atoms[i].adp, ucell)
        else:
            expij = 1
            atoms[i].adp = 'Uiso'
            #logging.error("wrong no of elements in atomlist")

        # Atomic form factors
        f = FormFactor(atoms[i].atomtype, stl)
        if disper == None or disper[atoms[i].atomtype] == None:
            fp = 0.0
            fpp = 0.0
        else:
            fp = disper[atoms[i].atomtype][0]
            fpp = disper[atoms[i].atomtype][1]

        for j in range(mysg.nsymop):
            # atomic displacement factor
            if atoms[i].adp_type == 'Uani':
                betaijrot = n.dot(mysg.rot[j], n.dot(betaij, mysg.rot[j]))
                expij = n.exp(-n.dot(hkl, n.dot(betaijrot, hkl)))

            # exponent for phase factor
            r = n.dot(mysg.rot[j], atoms[i].pos) + mysg.trans[j]
            exponent = 2 * n.pi * n.dot(hkl, r)

            #forming the real and imaginary parts of F
            s = n.sin(exponent)
            c = n.cos(exponent)
            site_pop = atoms[i].occ * atoms[i].symmulti / mysg.nsymop
            Freal = Freal + expij * (c * (f + fp) - s * fpp) * site_pop
            Fimg = Fimg + expij * (s * (f + fp) + c * fpp) * site_pop

    return [Freal, Fimg]
示例#6
0
    def check(self):
        '''
        This method will perform hughe amounts of tedious checks to try and
        catch bad input.
        '''
        self.missing = False
        self.errors = {}

        # check that all needed items are present
        for item in self.needed_items:
            if item not in self.param:
                #print self.needed_items[item]
                #self.missing = True
                self.errors[item] = self.needed_items[item]

        # set all non-read items to defaults
        for item in self.optional_items:
            if (item not in self.param):
                self.param[item] = self.optional_items[item]
            if (self.param[item] == []):
                self.param[
                    item] = self.optional_items[item] * self.param['no_voxels']

        # assert that the correct number of arguments are given
        for key in self.param:
            val = self.param[key]
            if val != None and key != 'output' and key != 'voxel_list':
                if key == 'peakshape':
                    if type(val) == type(1):
                        if val != 0:
                            self.errors[key] = 'Wrong number of arguments'
                        else:
                            val = [0, 0]
                            self.param[key] = val
                    else:
                        if len(val) > 5:
                            self.errors[key] = 'Wrong number of arguments'
                elif key == 'sample_cyl' or key == 'gen_pos':
                    if len(val) != 2:
                        self.errors[key] = 'Wrong number of arguments'
                elif key == 'sample_xyz' or 'pos_voxels' in key:
                    if len(val) != 3:
                        self.errors[key] = 'Wrong number of arguments'
                elif 'gen_size' in key:
                    if len(val) != 4:
                        self.errors[key] = 'Wrong number of arguments'
                elif 'gen_eps' in key:
                    if type(val) == type(1):
                        if val != 0:
                            self.errors[key] = 'Wrong number of arguments'
                    else:
                        if len(val) != 5:
                            self.errors[key] = 'Wrong number of arguments'
                elif key == 'gen_phase':
                    try:
                        dummy = len(val)
                    except:
                        val = [val]
                        self.param[key] = val
                    if len(val) < 1:
                        self.errors[key] = 'Wrong number of arguments'
                elif key == 'unit_cell' or 'eps_voxels' in key:
                    if len(val) != 6:
                        self.errors[key] = 'Wrong number of arguments'
                elif 'U_voxels' in key:
                    if len(val) != 3:
                        if len(val) != 9:
                            self.errors[key] = 'Wrong number of arguments'
                        else:
                            self.param[key] = n.array(self.param[key])
                            self.param[key].shape = (3, 3)
                    else:
                        if val.shape != (3, 3):
                            self.errors[key] = 'Wrong number of arguments'
                    # reshape U-matrices
            elif key == 'output':
                for item in val:
                    if item not in self.output_types:
                        self.errors[
                            key] = 'Output type given %s is not an option' % item

        # Check no of phases
        no_phases = self.param['no_phases']

        phase_list_structure = []
        phase_list_unit_cell = []
        phase_list_sgno = []
        phase_list_sgname = []
        phase_list_gen_size = []
        phase_list_gen_eps = []
        phase_list = []

        for item in self.param:
            if '_phase_' in item:
                if 'structure' in item:
                    phase_list_structure.append(eval(item.split('_phase_')[1]))
                elif 'unit_cell' in item:
                    phase_list_unit_cell.append(eval(item.split('_phase_')[1]))
                elif 'sgno' in item:
                    phase_list_sgno.append(eval(item.split('_phase_')[1]))
                elif 'sgname' in item:
                    phase_list_sgname.append(eval(item.split('_phase_')[1]))
                elif 'gen_size' in item:
                    phase_list_gen_size.append(eval(item.split('_phase_')[1]))
                elif 'gen_eps' in item:
                    phase_list_gen_eps.append(eval(item.split('_phase_')[1]))

        phase_list_structure.sort()
        phase_list_unit_cell.sort()
        phase_list_sgno.sort()
        phase_list_sgname.sort()
        phase_list_gen_size.sort()
        phase_list_gen_eps.sort()

        if len(phase_list_structure) != 0:
            if len(phase_list_structure) != no_phases:
                self.errors['phase_list_structure'] = \
                    'Input number of structural phases does not agree with number\n' +\
                    ' of structure_phase, check for multiple names or missing files.'
            else:
                phase_list = phase_list_structure
        elif len(phase_list_unit_cell) != 0:
            if len(phase_list_unit_cell) != no_phases:
                self.errors['phase_list_unit_cell'] = \
                    'Input number of structural phases does not agree with number\n' +\
                    ' of unit_cell, check for multiple names or missing linies.'
            else:
                phase_list = phase_list_unit_cell
            if len(phase_list_sgno) == 0:
                if len(phase_list_sgname) != no_phases:
                    self.errors['phase_list_sgname'] = \
                        'Input number of structural phases does not agree with number\n' +\
                        'of space group information given (sgno or sgname),\n' +\
                        'check for multiple names or missing linies.'
                if phase_list_sgname != phase_list_unit_cell:
                    self.errors['phase_list_sgname_2'] = \
                        'The phase numbers given to unit_cell does not match those in sgname'

                # add sgno for phase to parameter list
                for phase in phase_list_sgname:
                    self.param['sgno_phase_%i' % phase] = sg.sg(
                        sgname=self.param['sgname_phase_%i' % phase]).no
                    self.param['cell_choice_phase_%i' % phase] = sg.sg(
                        sgname=self.param['sgname_phase_%i' %
                                          phase]).cell_choice

            elif len(phase_list_sgname) == 0:
                if len(phase_list_sgno) != no_phases:
                    self.errors['phase_list_sgno'] = \
                        'Input number of structural phases does not agree with number\n' +\
                        'of space group information given (sgno or sgname),\n' +\
                        'check for multiple names or missing linies.'
                if phase_list_sgno != phase_list_unit_cell:
                    self.errors['phase_list_sgno_2'] = \
                        'The phase numbers given to unit_cell does not match those in sgno.'

                # add sgname for phase to parameter list
                for phase in phase_list_sgno:
                    try:
                        self.param['cell_choice_phase_%i' % phase] = sg.sg(
                            sgno=self.param['sgno_phase_%i' % phase],
                            cell_choice=self.param['cell_choice_phase_%i' %
                                                   phase]).cell_choice
                    except:
                        self.param['cell_choice_phase_%i' % phase] = sg.sg(
                            sgno=self.param['sgno_phase_%i' %
                                            phase]).cell_choice
                    self.param['sgname_phase_%i' % phase] = sg.sg(
                        sgno=self.param['sgno_phase_%i' % phase],
                        cell_choice=self.param['cell_choice_phase_%i' %
                                               phase]).name
            else:
                # both sg numbers and names in input check if they point at the same space group
                for phase in phase_list_sgno:
                    if self.param['sgname_phase_%i' % phase] != sg.sg(
                            sgno=self.param['sgno_phase_%i' % phase]).name:
                        self.errors['sgname_phase_list_sgno_2'] = \
                            '\nSpace group is specified both as space group name and number - \n' + \
                            'and they do not correspond to the same space group. \n' + \
                            'Please sort this out in the input file for phase %i.' %phase

        if len(phase_list_gen_size) != 0:
            if len(phase_list_gen_size) != no_phases:
                self.errors['phase_list_gen_size_1'] = \
                    'Input number of structural phases does not agree with number\n' +\
                    'of gen_size_phase_ keywords given'

            if phase_list_gen_size != phase_list:
                self.errors['phase_list_gen_size_2'] = \
                    'The phase numbers given to gen_size_phase does not match those\n' +\
                    'in crystallographic part - structure_phase_X or unit_cell_phase_X.'
            self.param['gen_size'][0] = 1
        else:
            if len(phase_list) > 0:
                for phase in phase_list:
                    self.param['gen_size_phase_%i' % phase] = copy(
                        self.param['gen_size'])
            else:
                phase = 0
                self.param['gen_size_phase_%i' % phase] = copy(
                    self.param['gen_size'])

        if len(phase_list_gen_eps) != 0:
            if len(phase_list_gen_eps) != no_phases:
                self.errors['phase_list_gen_eps_1'] = \
                    'Input number of structural phases does not agree with number\n' +\
                    'of gen_size_phase_ keywords given'
            if phase_list_gen_eps != phase_list:
                self.errors['phase_list_gen_eps_2'] = \
                    'The phase numbers given to gen_size_phase does not match those\n' +\
                    'in crystallographic part - structure_phase_X or unit_cell_phase_X.'
            self.param['gen_eps'][0] = 1
        else:
            if len(phase_list) > 0:
                for phase in phase_list:
                    self.param['gen_eps_phase_%i' % phase] = copy(
                        self.param['gen_eps'])
            else:
                phase = 0
                # If strain is not provided and no generation of strains have be asked for
                # "set" all eps to zero.
                if self.param['gen_eps'][0] == 0:
                    self.param['gen_eps'] = [1, 0.0, 0.0, 0.0, 0.0]
                self.param['gen_eps_phase_%i' % phase] = copy(
                    self.param['gen_eps'])
        if self.param['gen_phase'][0] != 0:
            if len(self.param['gen_phase'][1:]) != no_phases * 2:
                self.errors['gen_phase'] = 'Missing info for  -  gen_phase'

        # Make sure both sgname and sgno exist
        if len(phase_list_sgno) == 0:
            for phase in phase_list_sgno:
                self.param['sgno_phase_%i' % phase] = sg.sg(
                    sgname=self.param['sgname_phase_%i' % phase]).no
        if len(phase_list_sgname) == 0:
            for phase in phase_list_sgname:
                self.param['sgname_phase_%i' % phase] = sg.sg(
                    sgno=self.param['sgno_phase_%i' % phase],
                    cell_choice=self.param['cell_choice_phase_%i' %
                                           phase]).name

        # Init no of voxels belonging to phase X if not generated
        if self.param['gen_phase'][0] != 1:
            if len(phase_list) == 0:
                self.param['no_voxels_phase_0'] = self.param['no_voxels']
            else:
                for phase in phase_list:
                    self.param['no_voxels_phase_%i' % phase] = 0
        else:
            for i in range(self.param['no_phases']):
                phase = self.param['gen_phase'][i * 2 + 1]
                no_voxels_phase = int(self.param['gen_phase'][i * 2 + 2])
                self.param['no_voxels_phase_%i' % phase] = no_voxels_phase

        # read U, pos, eps and size for all voxels
        voxel_list_U = []
        voxel_list_pos = []
        voxel_list_eps = []
        voxel_list_size = []
        voxel_list_phase = []
        no_voxels = self.param['no_voxels']

        for item in self.param:
            if '_voxels_' in item:
                if 'U' in item:
                    voxel_list_U.append(eval(item.split('_voxels_')[1]))
                elif 'pos' in item:
                    voxel_list_pos.append(eval(item.split('_voxels_')[1]))
                elif 'eps' in item:
                    voxel_list_eps.append(eval(item.split('_voxels_')[1]))
                elif 'size' in item:
                    voxel_list_size.append(eval(item.split('_voxels_')[1]))
                elif 'phase' in item[:5]:
                    voxel_list_phase.append(eval(item.split('_voxels_')[1]))
                    self.param['no_voxels_phase_%i' % self.param[item]] += 1

        sum_of_voxels = 0
        if self.param['no_phases'] > 1:
            for phase in phase_list:
                sum_of_voxels += self.param['no_voxels_phase_%i' % phase]
            if sum_of_voxels != no_voxels:
                self.errors['no_voxels_2'] = \
                    'Input number of voxels (%i) does not agree ' %no_voxels +\
                    'with number of phase_voxels_ keywords (%i)' %sum_of_voxels
        else:
            self.param['no_voxels_phase_0'] = no_voxels

        # assert that input U, pos, eps size are correct in format
        # (same number of voxels and same specifiers or else not input)
        voxel_list_U.sort()
        voxel_list_pos.sort()
        voxel_list_eps.sort()
        voxel_list_size.sort()
        voxel_list_phase.sort()
        if len(voxel_list_U) != 0 and self.param['gen_U'] == 0:
            if len(voxel_list_U) != no_voxels:
                self.errors['voxel_list_U'] = \
                    'Input number of voxels (%i) does not agree with number\n'  %no_voxels +\
                    ' of U_voxels (%i), check for multiple names' %len(voxel_list_U)
            self.param['voxel_list'] = voxel_list_U
            if len(voxel_list_pos) != 0 and self.param['gen_pos'][0] == 0:
                if voxel_list_U != voxel_list_pos:
                    self.errors['voxel_list_U_pos'] = \
                        'Specified voxel numbers for U_voxels and pos_voxels disagree'
                if len(voxel_list_eps) != 0 and self.param['gen_eps'][0] == 0:
                    if voxel_list_U != voxel_list_eps:
                        self.errors['voxel_list_U_eps'] = \
                            'Specified voxel numbers for U_voxels and eps_voxels disagree'
                if len(voxel_list_size
                       ) != 0 and self.param['gen_size'][0] == 0:
                    if voxel_list_U != voxel_list_size:
                        self.errors['voxel_list_U_size'] = \
                            'Specified voxel numbers for U_voxels and size_voxels disagree'
                if len(voxel_list_phase
                       ) != 0 and self.param['gen_phase'][0] == 0:
                    if voxel_list_U != voxel_list_phase:
                        self.errors['voxel_list_U_phase'] = \
                            'Specified voxel numbers for U_voxels and phase_voxels disagree'
        else:
            if len(voxel_list_pos) != 0 and self.param['gen_pos'][0] == 0:

                if len(voxel_list_pos) != no_voxels:
                    self.errors['voxel_list_pos_novoxels'] = \
                        'Input number of voxels does not agree with number\n'+\
                        ' of pos_voxels, check for multiple names'
                self.param['voxel_list'] = voxel_list_pos
                if len(voxel_list_eps) != 0 and self.param['gen_eps'][0] == 0:

                    if voxel_list_pos != voxel_list_eps:
                        self.errors['voxel_list_pos_eps'] = \
                            'Specified voxel number for pos_voxels and eps_voxels disagree'
                if len(voxel_list_size
                       ) != 0 and self.param['gen_size'][0] == 0:

                    if voxel_list_pos != voxel_list_size:
                        self.errors['voxel_list_pos_size'] = \
                            'Specified voxel number for pos_voxels and size_voxels disagree'
                if len(voxel_list_phase
                       ) != 0 and self.param['gen_phase'][0] == 0:

                    if voxel_list_pos != voxel_list_phase:
                        self.errors['voxel_list_pos_phase'] = \
                            'Specified voxel number for pos_voxels and phase_voxels disagree'
            elif len(voxel_list_eps) != 0 and self.param['gen_eps'][0] == 0:

                if len(voxel_list_eps) != no_voxels:
                    self.errors['voxel_list_eps_novoxels'] = \
                        'Input number of voxels does not agree with number'+\
                        ' of eps_voxels, check for multiple names'
                self.param['voxel_list'] = voxel_list_eps
                if len(voxel_list_size
                       ) != 0 and self.param['gen_size'][0] == 0:

                    if voxel_list_eps != voxel_list_size:
                        self.errors['voxel_list_eps_size'] = \
                            'Specified voxel number for eps_voxels and size_voxels disagree'
                if len(voxel_list_phase
                       ) != 0 and self.param['gen_phase'][0] == 0:

                    if voxel_list_eps != voxel_list_phase:
                        self.errors['voxel_list_eps_phase'] = \
                            'Specified voxel number for eps_voxels and phase_voxels disagree'
            elif len(voxel_list_size) != 0 and self.param['gen_size'][0] == 0:

                if len(voxel_list_size) != no_voxels:
                    self.errors['voxel_list_size_novoxels'] = \
                        'Input number of voxels does not agree with number\n'+\
                        ' of size_voxels, check for multiple names'
                self.param['voxel_list'] = voxel_list_size
                if len(voxel_list_phase
                       ) != 0 and self.param['gen_phase'][0] == 0:

                    if voxel_list_size != voxel_list_phase:
                        self.errors['voxel_list_size_phase'] = \
                            'Specified voxel numbers for size_voxels and' +\
                            'phase_voxels disagree'
            elif len(
                    voxel_list_phase) != 0 and self.param['gen_phase'][0] == 0:

                if len(voxel_list_phase) != no_voxels:
                    self.errors['voxel_list_phase_novoxels'] = \
                        'Input number of voxels does not agree with number\n'+\
                        ' of phase_voxels, check for multiple names'
                self.param['voxel_list'] = voxel_list_phase
            else:
                self.param['voxel_list'] = list(range(no_voxels))

        if len(voxel_list_U) == 0 and self.param['gen_U'] == 0:
            self.errors['voxel_list_gen_U'] = \
                'Information on U generations missing'
        if len(voxel_list_pos) == 0 and self.param['gen_pos'][0] == 0:
            self.errors['voxel_list_gen_pos'] = \
                'Information on position generation missing'

        if len(voxel_list_size) == 0 and self.param['gen_size'][0] == 0:
            self.errors['voxel_list_gen_size'] = \
                'Information on voxel size generation missing'

        #If no structure file is given - unit_cel should be
        if len(phase_list) == 0:
            # This is a monophase simulation probably using the "old" keywords
            if self.param['structure_file'] == None:
                if self.param['unit_cell'] == None:
                    self.errors['unit_cell'] = \
                        'Missing input: either structure_file or unit_cell has to be specified'

                # rename keyword
                self.param['unit_cell_phase_0'] = self.param['unit_cell']
                # and delete old one
                del self.param['unit_cell']
                if self.param['sgno'] == None and self.param['sgname'] == None:
                    self.errors['sgno'] = \
                        'Missing input: no space group information, '+\
                        'please input either sgno or sgname'
                if self.param['sgno'] == None:
                    self.param['sgno_phase_0'] = sg.sg(
                        sgname=self.param['sgname']).no
                    self.param['cell_choice_phase_0'] = sg.sg(
                        sgname=self.param['sgname']).cell_choice
                    # rename keyword
                    self.param['sgname_phase_0'] = self.param['sgname']
                    # and delete old one
                    del self.param['sgname']
                else:
                    try:
                        self.param['cell_choice_phase_0'] = sg.sg(
                            sgno=self.param['sgno'],
                            cell_choice=self.param['cell_choice']).cell_choice
                        del self.param['cell_choice']
                    except:
                        self.param['cell_choice_phase_0'] = sg.sg(
                            sgno=self.param['sgno']).cell_choice
                    self.param['sgname_phase_0'] = sg.sg(
                        sgno=self.param['sgno'],
                        cell_choice=self.param['cell_choice_phase_0']).name
                    # rename keyword
                    self.param['sgno_phase_0'] = self.param['sgno']
                    # and delete old one
                    del self.param['sgno']
            else:
                # rename keyword
                self.param['structure_phase_0'] = self.param['structure_file']
                # and delete old one
                del self.param['structure_file']
            phase_list = [0]
        self.param['phase_list'] = phase_list

        # make old inp files work
        if len(voxel_list_phase) == 0 and self.param['no_phases'] == 1:
            self.param['voxel_list_phase_%i' %
                       self.param['phase_list'][0]] = self.param['voxel_list']

        if self.param['sample_xyz'] != None and self.param[
                'sample_cyl'] != None:
            self.errors['sample_dim'] = \
                'Both sample_xyz and sample_cyl are given'

        if self.param['gen_size'][0] != 0:
            for phase in phase_list:
                phase_key = 'gen_size_phase_%i' % phase

                if self.param[phase_key][1] == 0:
                    self.errors[
                        'phase_key_1'] = 'Invalid gen_size command, mean size 0'
                if self.param[phase_key][1] > 0:

                    if self.param[phase_key][2] > self.param[phase_key][1]:
                        self.errors['phase_key_2'] = \
                            'gen_size (phase %i): the minimum voxel size is made larger than the mean voxel size - it should be smaller' %phase
                    if self.param[phase_key][3] < self.param[phase_key][1]:
                        self.errors['phase_key_3'] = \
                            'gen_size (phase %i): the maximum voxel size is made smaller than the mean voxel size - it should be larger' %phase
                    if self.param[phase_key][2] < 0:
                        self.param[phase_key][2] = 0

        #check that the given voxel_size and no_voxels are consistent with sample_vol, adjust max to sample size
        if self.param['sample_xyz'] != None:

            if self.param['sample_xyz'][0] < 0 or \
                    self.param['sample_xyz'][1] < 0 or \
                    self.param['sample_xyz'][2] < 0:
                self.errors[
                    'sample_xyz'] = 'Invalid sample_xyz all values should be positive'
                self.param['sample_vol'] = None
            else:
                self.param['sample_vol'] = self.param['sample_xyz'][0]*\
                    self.param['sample_xyz'][1]*\
                    self.param['sample_xyz'][2]
                sample_min_dim = min(self.param['sample_xyz'])
        elif self.param['sample_cyl'] != None:

            if self.param['sample_cyl'][0] <= 0 or \
                    self.param['sample_cyl'][1] <= 0:
                self.errors['sample_cyl'] = \
                    'Invalid sample_cyl <= 0'
                self.param['sample_vol'] = None
            else:
                self.param['sample_vol'] = n.pi*self.param['sample_cyl'][0]*\
                    self.param['sample_cyl'][0]*self.param['sample_cyl'][1]/4.
            sample_min_dim = min(self.param['sample_cyl'])
        else:
            self.param['sample_vol'] = n.inf

        if self.param['sample_vol'] != None and self.param['gen_size'][0] != 0:
            diam_limit = (6*self.param['sample_vol']/\
                         (n.exp(.5)*n.pi*self.param['no_voxels']))**(1/3.)
            mean_diam = 0
            vol = []
            for phase in phase_list:

                weight = self.param['no_voxels_phase_%i' %
                                    phase] / self.param['no_voxels']
                vol.append(abs(self.param['gen_size_phase_%i' %phase][1])**3 *\
                               n.pi/6.* self.param['no_voxels_phase_%i' %phase])
                mean_diam += abs(
                    self.param['gen_size_phase_%i' % phase][1]) * weight
            for i in range(self.param['no_phases']):
                self.param['vol_frac_phase_%i' %
                           phase_list[i]] = vol[i] / n.sum(vol)

            if mean_diam > diam_limit:
                self.errors['mean_diam'] = \
                    'The sample volume is too small to contain the '+\
                    'specified number of voxels with the given voxel size'
            if len(voxel_list_size) > 0:
                for i in range(len(voxel_list_size)):

                    if self.param['size_voxels_%s' %
                                  (self.param['voxel_list'][i])] >= diam_limit:
                        self.errors['size_voxels_%s' %(self.param['voxel_list'][i])] = \
                            'The sample diameter is too small to contain the size of the voxel ' +\
                            'by size_voxels_%s' %(self.param['voxel_list'][i])

        #check that a file name with the odf file is input is odf_type chosen to be 2.
        if self.param['peakshape'][0] == 2:
            if self.param['odf_type'] == 2:
                assert self.param[
                    'odf_file'] != None, 'No filename given for ODF'