biotite.structure.io.gro.GROFile

class biotite.structure.io.gro.GROFile[source]

Bases: TextFile

This class represents a GRO file.

This class only provides support for reading/writing the pure atom information

Examples

Load a \*.gro file, modify the structure and save the new structure into a new file:

>>> import os.path
>>> file = GROFile.read(os.path.join(path_to_structures, "1l2y.gro"))
>>> array_stack = file.get_structure()
>>> array_stack_mod = rotate(array_stack, [1,2,3])
>>> file = GROFile()
>>> file.set_structure(array_stack_mod)
>>> file.write(os.path.join(path_to_directory, "1l2y_mod.gro"))
copy()

Create a deep copy of this object.

Returns
copy

A copy of this object.

get_model_count()

Get the number of models contained in this GRO file.

Returns
model_countint

The number of models.

get_structure(model=None)

Get an AtomArray or AtomArrayStack from the GRO file.

Parameters
modelint, optional

If this parameter is given, the function will return an AtomArray from the atoms corresponding to the given model number (starting at 1). Negative values are used to index models starting from the last model insted of the first model. If this parameter is omitted, an AtomArrayStack containing all models will be returned, even if the structure contains only one model.

Returns
arrayAtomArray or AtomArrayStack

The return type depends on the model parameter.

classmethod read(file, *args, **kwargs)

Parse a file (or file-like object).

Parameters
filefile-like object or str

The file to be read. Alternatively a file path can be supplied.

Returns
file_objectFile

An instance from the respective File subclass representing the parsed file.

static read_iter(file)

Create an iterator over each line of the given text file.

Parameters
filefile-like object or str

The file to be read. Alternatively a file path can be supplied.

Yields
linestr

The current line in the file.

set_structure(array)

Set the AtomArray or AtomArrayStack for the file.

Parameters
arrayAtomArray or AtomArrayStack

The array or stack to be saved into this file. If a stack is given, each array in the stack is saved as separate model.

write(file)

Write the contents of this object into a file (or file-like object).

Parameters
filefile-like object or str

The file to be written to. Alternatively a file path can be supplied.

static write_iter(file, lines)

Iterate over the given lines of text and write each line into the specified file.

In contrast to write(), each line of text is not stored in an intermediate TextFile, but is directly written to the file. Hence, this static method may save a large amount of memory if a large file should be written, especially if the lines are provided as generator.

Parameters
filefile-like object or str

The file to be written to. Alternatively a file path can be supplied.

linesgenerator or array-like of str

The lines of text to be written. Must not include line break characters.