Creating a Field

Field class

Defines the main Field class object

class fieldkit.field.Field(npw=None, data=None, h=None)[source]

Bases: object

Class for Field object used to model 1D, 2D, 3D structures.

npw

number of grid points in each dimension

npw_total

total number of grid points for all dimensions

dim

dimension of field

data

stored values of field at each grid point

h

a cell tensor, in which the columns are box vectors that describe the coordinate system

is_real_space

tells if Fourier transform has been used

coords

stores x,y,z coordinates of each grid point

CoordsFromH()[source]

Compute coordinates of field from current “h” box vector.

hvoxel()[source]
is_complex()[source]

return if field is complex or not

is_cubic()[source]

is cell of this field cubic or not

is_orthorhombic()[source]
set_coords(coords)[source]

User can manually set coords.

set_data(data)[source]

Sets data based on size.

set_h(h)[source]

Checks that h is square and sets coords.

volume()[source]

calculate volume of cell tensor

Reading and Writing Functions

All functions are found in field_io.py

Functions to read/write fields to files

fieldkit.fileio.read_from_file(filename)[source]

Reads from textfile and output a list of Field objects. Adapted from iotools.py.

Parameters:

filename – String for name of file to be read through this function.

Returns:

A list of Fields objects.

Return type:

field_list

fieldkit.fileio.write_to_VTK(filename, fields)[source]

Creates a VTK file based on the fields variable. Adapted from FTS-tools/plot/PolyFTS_to_VTK.py.

Parameters:
  • filename – String for name of file to be written through this function.

  • fields – A list of Fields objects.

Returns:

A VTK file based on fields.

fieldkit.fileio.write_to_file(filename, fields)[source]

Creates a text file based on the fields variable. Adapted from iotools.py.

Parameters:
  • filename – String for name of file to be written through this function.

  • fields – A list of Fields objects.

Returns:

A text file based on fields.

Raises:

TypeError – if fields is not a list, than make it a one element list.

Example

Uses all three functions from above to create a Field object from density.dat and create dat and VTK files for the Field object:

import fieldkit as fk

filename = "density.dat"

fields = fk.read_from_file(filename)
fk.write_to_file("tmp.dat", fields)
fk.write_to_VTK("density.vtk", fields)

Output

_images/example_read_output.png

density.vtk (left) and tmp.dat(right) are the putput files of write_to_VTK and write_to_file functions, respeictively