Beispiel #1
0
def parse_band_eigenenergy_file(file_handler):
    """ The main workhorse of this program.
    Parses the given file with eigenenergy information from Abinit
    The file format is as follows, with variables in <>:
        Eigenvalues ( <energy_unit> ) for nkpt= <num_k_points> k points:
        <k points>
    Each k point is described on two lines, as follows
        kpt#    <number>, nband=    <num_bands>, wtk=    <wtk>, kpt=  <x1> <x2> <x3> (<coord system>)
        <band1_energy>  <band2_energy> ...

    This function returns an array of KPointWithEnergy objects
    """
    first_line = file_handler.readline()
    num_k_points, energy_unit = parse_num_k_points_and_energy_unit_from_first_line(
        first_line)
    k_points = []
    for k_point in xrange(
            1, num_k_points +
            1):  # +1 because range and xrange have exlusive maxes
        line_one = file_handler.readline()
        number, num_bands, wtk, coord = parse_k_point_line_one_for_number_nband_wtk_coord(
            line_one)
        assert number == k_point
        band_energies = []
        while len(band_energies) < num_bands:
            band_energies.extend(
                parse_line_for_k_point_band_energies(file_handler.readline()))
        k_points.append(
            KPointWithEnergy(number, num_bands, wtk, coord, band_energies,
                             energy_unit))
    handle_command_line_IO.errprint(k_points)
    return k_points
Beispiel #2
0
def display_help_function():
    """
    displays usage information for this file
    """
    handle_command_line_IO.errprint(\
    	'Usage: [echo input_file.abinit.json | ] '+\
    	'python generate_cell_xyz_rhombus.py [input_file.abinit.json]')
Beispiel #3
0
def main():
    """
    Reads an experiment .abinit.json from stdin or from the file marked in the first argument,
    and copies the unit cell in each cardinal direction according to the value
    in "meta.repeat_cell", modifiying "meta.atoms" and "direct.acell".
    Outputs in .abinit.json format to stdout.
    """
    # Get input from stdin or first argument's file
    with handle_command_line_IO.get_input_file(
            display_help_message) as input_file:
        experiment = Experiment.load_from_json_file(input_file)

        # Make this transparent; if no scaling is specified, don't scale
        if experiment.meta and 'dopings' in experiment.meta and 'atoms' in experiment.meta:

            # Get the atoms and dopings, remove the dopings
            experiment.meta['atoms'] = \
                dope_atoms(parse_atoms(experiment.meta['atoms']),
                           parse_atoms(experiment.meta.pop('dopings', None)),
                           tolerance=1e-4)
        else:
            handle_command_line_IO.errprint(
                "No doping of unit cell specified; taking no action")

        # Echo the resulting experiment back to stdout
        print json.dumps(experiment, cls=SimpleObjectJSONEncoder, indent=4)
Beispiel #4
0
def main():
    """
    Reads an experiment .abinit.json from stdin or from the file marked in the first argument,
    and copies the unit cell in each cardinal direction according to the value
    in "meta.repeat_cell", modifiying "meta.atoms" and "direct.acell".
    Outputs in .abinit.json format to stdout.
    """
    # Get input from stdin or first argument's file
    with handle_command_line_IO.get_input_file(
            display_help_message) as input_file:
        experiment = Experiment.load_from_json_file(input_file)

        # Make this transparent; if no scaling is specified, don't scale
        if experiment.meta and 'repeat_cell' in experiment.meta and 'atoms' in experiment.meta:
            # Get the number of times to repeat
            repeat_factor = experiment.meta['repeat_cell']
            if isinstance(repeat_factor, list):
                if len(repeat_factor) != 3:
                    raise RuntimeError("Unit cell must be 3-D.")
            else:
                # if this throws an error, just report it to the user
                repeat_factor = [int(repeat_factor)] * 3

            # Repeat the atoms
            experiment.meta['atoms'] = \
                repeat_atoms_in_unit_cell(parse_atoms(experiment.meta['atoms']), repeat_factor)

            # Scale the unit cell
            for attribute in experiment.direct:
                if attribute.name == "acell":
                    attribute.value = [
                        float(attribute.value[i]) * repeat_factor[i]
                        for i in xrange(0, 3)
                    ]

            # Take out repetition of cell so it doesn't happen again somehow
            experiment.meta.pop('repeat_cell', None)
        else:
            handle_command_line_IO.errprint(
                "No repeat of unit cell specified; taking no action")

        # Echo the resulting experiment back to stdout
        print json.dumps(experiment, cls=SimpleObjectJSONEncoder, indent=4)
def main():
    """
    Reads an experiment .abinit.json from stdin or from the file marked in the first argument,
    and generates a 2-D chiral tesselation of the cell according to the values in
    in "meta.make_chirality", modifiying "meta.atoms" and "direct.acell".
    Outputs in .abinit.json format to stdout.
    """
    # Get input from stdin or first argument's file
    with handle_command_line_IO.get_input_file(display_help_message) as input_file:
        experiment = Experiment.load_from_json_file(input_file)

        # Make this transparent; if no scaling is specified, don't scale
        if experiment.meta and 'make_chirality' in experiment.meta and 'atoms' in experiment.meta:
            # Get the number of times to repeat
            desired_chirality = experiment.meta.pop('make_chirality', None)
            if not isinstance(desired_chirality, list) or len(desired_chirality) != 2:
                raise RuntimeError("Desired chirality must be 2-D.")

            rhombus_basis = [[1, 0.5, 0], [0, 3**0.5/2, 0], [0, 0, 1]]

            original_number_of_atoms = len(experiment.meta['atoms'])

            # Repeat the atoms
            experiment.meta['atoms'] = \
                generate_xy_chiral_cell(parse_atoms(experiment.meta['atoms']), desired_chirality, rhombus_basis)

            # Scale the unit cell
            normalization_factor = (desired_chirality[0] ** 2 + desired_chirality[1] ** 2) ** 0.5
            for attribute in experiment.direct:
                if attribute.name == "acell":
                    attribute.value = \
                        [attribute.value[0] * normalization_factor, \
                         attribute.value[1] * normalization_factor, \
                         attribute.value[2]]

            # Validate  (because chirality is easy to screw up)
            # Make sure there are no collisions
            for collision in get_collisions(experiment.meta['atoms']):
                handle_command_line_IO.errprint(\
                    "collision between "+str(collision[0])+" and "+str(collision[1]))
            # Make sure there are the right number of atoms
            expected_number_of_atoms = original_number_of_atoms * sum([x*x for x in desired_chirality])
            if expected_number_of_atoms != len(experiment.meta['atoms']):
                handle_command_line_IO.errprint('WARNING\nExpected '+str(expected_number_of_atoms)+\
                                   ' atoms, found '+str(len(experiment.meta['atoms'])))


        else:
            handle_command_line_IO.errprint("No chirality of unit cell specified; taking no action")

        # Echo the resulting experiment back to stdout
        print json.dumps(experiment, cls=SimpleObjectJSONEncoder, indent=4)
Beispiel #6
0
def display_help():
    handle_command_line_IO.errprint("Usage: python graph_band_eigenvalues.py [abinit_eigenvalue_data.json [point_label_index point_label ...]]> abinit_eigenvalue_data.svg")
def display_help_message():
    """Prints a help message with usage instructions to stderr"""
    handle_command_line_IO.errprint(
        "Usage: [cat input1.abinit.json | ] python merge.py [input2.abinit.json ... ] > [outfile.abinit.json]"
    )
Beispiel #8
0
def err_print_help_message():
    """Prints a short help message describing how to use this program"""
    handle_command_line_IO.errprint(
        "Usage: parse_band_eigenvalues.py <filename>")
def display_help_message():
    """Prints a help message with usage instructions to stderr"""
    handle_command_line_IO.errprint("Usage: python convert_abinit_input_from_atoms_to_direct.py"\
        +" [infile.abinit.json] > [outfile.abinit.json]")
Beispiel #10
0
def display_help_message():
    """Prints a help message with usage instructions to stderr"""
    handle_command_line_IO.errprint(
        "Usage: python generate_abinit_input_file_from_json.py [filename.abinit.json] > outputfile.in"
    )