コード例 #1
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)
コード例 #2
0
def main():
    """
    Displays the atoms from the meta attributes of the input experiment within a rhombal unit cell
    """
    with handle_command_line_IO.get_input_file(
            display_help_function) as input_file:
        experiment = Experiment.load_from_json_file(input_file)
        atoms = parse_atoms(experiment.meta['atoms'])
        display_atoms_rhombus(atoms)
コード例 #3
0
def main():
    """
    Accepts input on stdin or from the file specified in the first argument,
    reads band eigenenergy data output from ABINIT,
    and outputs a JSON file representing the data in JSON.
    """
    with handle_command_line_IO.get_input_file(
            err_print_help_message) as input_file:
        print json.dumps(parse_band_eigenenergy_file(input_file),
                         cls=SimpleObjectJSONEncoder)
コード例 #4
0
def main():
    """
    Read a .abinit.json file from stdin or a file specified in the first argument,
    Then print out its direct attributes, in UTF-8 encoding, to stdout as an ABINIT input file.
    """
    with handle_command_line_IO.get_input_file(
            display_help_message) as input_file:  #auto-close
        experiment = abinit_data_types.Experiment.load_from_json_file(
            input_file)
        print experiment.compile().encode(
            "UTF-8")  # send to stdout for redirection
コード例 #5
0
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)
コード例 #6
0
def main():
    """
    Displays the atoms from the meta attributes of the input experiment within a rhombal unit cell
    """
    with handle_command_line_IO.get_input_file(display_help_function) as input_file:
        experiment = Experiment.load_from_json_file(input_file)
        atoms = parse_atoms(experiment.meta['atoms'])
        rhomb_atoms = get_rhombal_cell(atoms)
        acell_raw = experiment.get_direct_property('acell')
        cell_size = [float(coord) for coord in acell_raw.value]
        correct_size_rhomb_atoms = [Atom(atom.znucl, atom.coord*cell_size) for atom in rhomb_atoms]
        print len(atoms)
        print '' #no comment on the file
        for atom in correct_size_rhomb_atoms:
            print repr_in_xyz(atom)
def main():
    with handle_command_line_IO.get_input_file(display_help_message) as input_file: # get from stdin or first argument's file
        experiment = Experiment.load_from_json_file(input_file)

    if experiment.meta and 'atoms' in experiment.meta : #allow for pass-through if there's nothing to do
        atoms = sorted(parse_atoms(experiment.meta['atoms']), key=lambda atom: atom.znucl) # sorted so we can group by znucl
        experiment.meta['atoms'] = None
        atom_types = OrderedSet([atom.znucl for atom in atoms])
        znucl_to_typat_mapping = dict((znucl, index+1) for index, znucl in enumerate(atom_types))

        experiment.direct.append(SimpleAttribute(name="natom", value=len(atoms), comment=GENERATED_VALUE_COMMENT))
        experiment.direct.append(SimpleAttribute(name="ntypat", value=len(atom_types), comment=GENERATED_VALUE_COMMENT))
        experiment.direct.append(SimpleAttribute(name="znucl", value=list(atom_types), comment=GENERATED_VALUE_COMMENT))
        experiment.direct.append(SimpleAttribute(name="typat", value=[znucl_to_typat_mapping[atom.znucl] for atom in atoms], comment=GENERATED_VALUE_COMMENT))
        experiment.direct.append(SimpleAttribute(name="xred", value=[atom.coord.coordinate_array for atom in atoms], comment=GENERATED_VALUE_COMMENT))

    print json.dumps(experiment, cls=SimpleObjectJSONEncoder, indent=4) 
コード例 #8
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)
コード例 #9
0
def main():
    """
    Displays the atoms from the meta attributes of the input experiment within a rhombal unit cell
    """
    with handle_command_line_IO.get_input_file(display_help_function) as input_file:
        print repr_experiment_in_cif(Experiment.load_from_json_file(input_file))