The nmrstarlib API Reference

Routines for working with BMRB NMR-STAR and PDB CIF formatted files.

This package includes the following modules:

nmrstarlib
This module provides the StarFile superclass and NMRStarFile and CIFFile which are python dictionary representation of a BMRB NMR-STAR file and PDB CIF file, respectively. Data can be accessed directly from the instance using bracket accessors. The nmrstarlib module relies on the bmrblex module for processing of tokens.
bmrblex
This module provides the bmrblex() generator that is responsible for the syntax analysis of BMRB NMR-STAR and PDB CIF files, processing word, number, single quoted, double quoted, multiline quoted tokens.
converter
This module provides the Converter class that is responsible for the conversion of NMR-STAR and CIF formatted files.
csviewer
This module provides the CSViewer class that visualizes chemical shift values from NMR-STAR files using the Graphviz (http://www.graphviz.org/) DOT Languge description and provides code example for utilizing the library.
noise
This module provides the NoiseGenerator class for adding random normal noise values to peaks in simulated peak list for NMR-STAR formatted files.
plsimulator
This module provides necessary interfaces in order to create a simulated PeakList from NMR-STAR formatted files.
translator
This module provides StarFileToStarFile for conversion between NMR-STAR/CIF and JSONized NMR-STAR/CIF formatted files and StarFileToPeakList for conversion of NMR-STAR formatted files into peak list files using chemical shift values and assignment information.
fileio
This module provides the read_files() generator to open files from different sources (single file/multiple files on a local machine, directory/archive of files, URL address of a file).

nmrstarlib.nmrstarlib

This module provides the StarFile superclass and NMRStarFile and CIFFile subclasses that store data from a single NMR-STAR file and CIF file in the form of an OrderedDict. Data can be accessed directly from the StarFile instance using bracket accessors.

The NMR-STAR format is a hierarchical dictionary containing data on NMR experiments. The data is divided into a series of “saveframes” which each contain a number of key-value pairs and “loops”.

Each “saveframe” has a unique name, which is used as the key in the dictionary, corresponding to another dictionary containing the information in the “saveframe”. Since “loops” in NMR-Star format do not have unique names, the keys for them inside the “saveframe” dictionary are simply “loop_0”, “loop_1”, etc.

The CIF format is another STAR-derived format that is similar to NMR-STAR, i.e. it contains key-value pairs of data and contains “loops” but does not have “saveframe” data organization.

nmrstarlib.nmrstarlib.update_constants(nmrstar2cfg='', nmrstar3cfg='', resonance_classes_cfg='', spectrum_descriptions_cfg='')[source]

Update constant variables.

Returns:None
Return type:None
class nmrstarlib.nmrstarlib.StarFile(*args, **kwds)[source]

StarFile class that stores the data from a single NMR-STAR or CIF file in the form of an OrderedDict.

__init__(*args, **kwds)[source]

StarFile initializer. Leave frame_categories as None to read everything. Otherwise it can be a list of saveframe categories to read, skipping the rest.

Parameters:source (str) – Source StarFile instance was created from - local file or URL address.
static read(filehandle, source)[source]

Read data into a StarFile instance.

Parameters:
Returns:

subclass of StarFile.

Return type:

NMRStarFile or CIFFile

write(filehandle, file_format)[source]

Write StarFile data into file.

Parameters:
  • filehandle (io.TextIOWrapper) – file-like object.
  • file_format (str) – Format to use to write data: nmrstar, cif, or json.
Returns:

None

Return type:

None

writestr(file_format)[source]

Write StarFile data into string.

Parameters:file_format (str) – Format to use to write data: nmrstar, cif, or json.
Returns:String representing the StarFile instance.
Return type:str
print_file(f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='', tw=3)[source]

Print StarFile into a file or stdout.

Parameters:
  • f (io.StringIO) – writable file-like stream.
  • file_format (str) – Format to use: nmrstar, cif, or json.
  • tw (int) – Tab width.
Returns:

None

Return type:

None

_to_json()[source]

Save StarFile into JSON string.

Returns:JSON string.
Return type:str
_to_star()[source]

Save StarFile into NMR-STAR or CIF formatted string.

Returns:NMR-STAR string.
Return type:str
static _is_nmrstar(string)[source]

Test if input string is in NMR-STAR format.

Parameters:string (str or bytes) – Input string.
Returns:Input string if in NMR-STAR format or False otherwise.
Return type:str or False
static _is_cif(string)[source]

Test if input string is in CIF format.

Parameters:string (str or bytes) – Input string.
Returns:Input string if in CIF format or False otherwise.
Return type:str or False
static _is_json(string)[source]

Test if input string is in JSON format.

Parameters:string (str or bytes) – Input string.
Returns:Input string if in JSON format or False otherwise.
Return type:str or False
class nmrstarlib.nmrstarlib.NMRStarFile(source='', frame_categories=None, *args, **kwds)[source]

NMRStarFile class that stores the data from a single NMR-STAR file in the form of an OrderedDict.

__init__(source='', frame_categories=None, *args, **kwds)[source]

NMRStarFile initializer. Leave frame_categories as None to read everything. Otherwise it can be a list of saveframe categories to read, skipping the rest.

Parameters:
  • source (str) – Source StarFile instance was created from - local file or URL address.
  • frame_categories (list) – List of saveframe names.
_build_file(nmrstar_str)[source]

Build NMRStarFile object.

Parameters:nmrstar_str (str or bytes) – NMR-STAR-formatted string.
Returns:instance of NMRStarFile.
Return type:NMRStarFile
_build_saveframe(lexer)[source]

Build NMR-STAR file saveframe.

Parameters:lexer (bmrblex()) – instance of the lexical analyzer.
Returns:Saveframe dictionary.
Return type:collections.OrderedDict
_build_loop(lexer)[source]

Build saveframe loop.

Parameters:lexer (bmrblex()) – instance of lexical analyzer.
Returns:Fields and values of the loop.
Return type:tuple
_skip_saveframe(lexer)[source]

Skip entire saveframe - keep emitting tokens until the end of saveframe.

Parameters:lexer (bmrblex) – instance of the lexical analyzer class.
Returns:None
Return type:None
print_file(f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='nmrstar', tw=3)[source]

Print NMRStarFile into a file or stdout.

Parameters:
  • f (io.StringIO) – writable file-like stream.
  • file_format (str) – Format to use: nmrstar or json.
  • tw (int) – Tab width.
Returns:

None

Return type:

None

print_saveframe(sf, f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='nmrstar', tw=3)[source]

Print saveframe into a file or stdout. We need to keep track of how far over everything is tabbed. The “tab width” variable tw does this for us.

Parameters:
  • sf (str) – Saveframe name.
  • f (io.StringIO) – writable file-like stream.
  • file_format (str) – Format to use: nmrstar or json.
  • tw (int) – Tab width.
Returns:

None

Return type:

None

print_loop(sf, sftag, f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='nmrstar', tw=3)[source]

Print loop into a file or stdout.

Parameters:
  • sf (str) – Saveframe name.
  • sftag (str) – Saveframe tag, i.e. field name.
  • f (io.StringIO) – writable file-like stream.
  • file_format (str) – Format to use: nmrstar or json.
  • tw (int) – Tab width.
Returns:

None

Return type:

None

chem_shifts_by_residue(amino_acids=None, atoms=None, amino_acids_and_atoms=None, nmrstar_version='3')[source]

Organize chemical shifts by amino acid residue.

Parameters:
  • amino_acids (list) – List of amino acids three-letter codes.
  • atoms (list) – List of BMRB atom type codes.
  • amino_acids_and_atoms (dict) – Amino acid and its atoms key-value pairs.
  • nmrstar_version (str) – Version of NMR-STAR format to use for look up chemical shifts loop.
Returns:

List of OrderedDict per each chain

Return type:

list of collections.OrderedDict

class nmrstarlib.nmrstarlib.CIFFile(source='', *args, **kwds)[source]

CIFFile class that stores the data from a single CIF file in the form of an OrderedDict.

__init__(source='', *args, **kwds)[source]

CIFFile initializer.

Parameters:source (str) – Source CIFFile instance was created from - local file or URL address.
_build_file(cif_str)[source]

Build CIFFile object.

Parameters:cif_str (str or bytes) – NMR-STAR-formatted string.
Returns:instance of CIFFile.
Return type:CIFFile
_build_loop(lexer)[source]

Build loop.

Parameters:lexer (bmrblex()) – instance of lexical analyzer.
Returns:Fields and values of the loop.
Return type:tuple
print_file(f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='cif', tw=0)[source]

Print CIFFile into a file or stdout.

Parameters:
  • f (io.StringIO) – writable file-like stream.
  • file_format (str) – Format to use: cif or json.
  • tw (int) – Tab width.
Returns:

None

Return type:

None

print_loop(loop_number, f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='cif', tw=0)[source]

Print loop into a file or stdout.

Parameters:
  • f (io.StringIO) – writable file-like stream.
  • file_format (str) – Format to use: cif or json.
  • tw (int) – Tab width.
Returns:

None

Return type:

None

exception nmrstarlib.nmrstarlib.InvalidToken(value)[source]
__init__(value)[source]

Initialize self. See help(type(self)) for accurate signature.

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

exception nmrstarlib.nmrstarlib.SkipSaveFrame[source]
__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

nmrstarlib.nmrstarlib.list_spectrums()[source]

List all available spectrum names that can be used for peak list simulation.

Returns:None
Return type:None
nmrstarlib.nmrstarlib.list_spectrum_descriptions(*args)[source]

List all available spectrum descriptions that can be used for peak list simulation.

Parameters:args (str) – Spectrum name(s), e.g. list_spectrum_descriptions(“HNCO”, “HNcoCACB”), leave empty to list everything.
Returns:None
Return type:None

nmrstarlib.bmrblex

This module provides bmrblex() lexical analyzer for BMRB NMR-STAR format syntax. It is implemented as Python generator-based state machine which generates (yields) token one at a time when next() is invoked on bmrblex() instance.

Simplified description of parsing rules:

  • Each word or number separated by whitespace characters is a separate BMRB token.
  • Each single quoted (‘) string is a separate BMRB token, it should start with a single quote (‘) and end with a single quote always followed by whitespace character(s).
  • Each double quoted (“) string is a separate BMRB token, it should start with a double quote (“) and end with a double quote always followed by whitespace character(s).
  • Single quoted and double quoted strings have to be processed separately.
  • Single quoted and double quoted strings are processed one character at a time.
  • Multiline strings start with a semicolon always followed by new line character and ending with a semicolon always followed by whitespace character(s).
  • Multiline strings are processed one line at a time.

Note

nmrstarlib.bmrblex.bmrblex(text)[source]

A lexical analyzer for the BMRB NMR-STAR format syntax.

Parameters:text (str or bytes) – Input text.
Returns:Current token.
Return type:str

nmrstarlib.converter

This module provides functionality for converting between the BMRB NMR-STAR/CIF format and its equivalent JSONized NMR-STAR/CIF format.

The following conversions are possible:

Local files:
  • One-to-one file conversions:
    • textfile - to - textfile
    • textfile - to - textfile.gz
    • textfile - to - textfile.bz2
    • textfile.gz - to - textfile
    • textfile.gz - to - textfile.gz
    • textfile.gz - to - textfile.bz2
    • textfile.bz2 - to - textfile
    • textfile.bz2 - to - textfile.gz
    • textfile.bz2 - to - textfile.bz2
    • textfile / textfile.gz / textfile.bz2 - to - textfile.zip / textfile.tar / textfile.tar.gz / textfile.tar.bz2 (TypeError: One-to-many conversion)
  • Many-to-many files conversions:
    • Directories:
      • directory - to - directory
      • directory - to - directory.zip
      • directory - to - directory.tar
      • directory - to - directory.tar.bz2
      • directory - to - directory.tar.gz
      • directory - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
    • Zipfiles:
      • zipfile.zip - to - directory
      • zipfile.zip - to - zipfile.zip
      • zipfile.zip - to - tarfile.tar
      • zipfile.zip - to - tarfile.tar.gz
      • zipfile.zip - to - tarfile.tar.bz2
      • zipfile.zip - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
    • Tarfiles:
      • tarfile.tar - to - directory
      • tarfile.tar - to - zipfile.zip
      • tarfile.tar - to - tarfile.tar
      • tarfile.tar - to - tarfile.tar.gz
      • tarfile.tar - to - tarfile.tar.bz2
      • tarfile.tar - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
      • tarfile.tar.gz - to - directory
      • tarfile.tar.gz - to - zipfile.zip
      • tarfile.tar.gz - to - tarfile.tar
      • tarfile.tar.gz - to - tarfile.tar.gz
      • tarfile.tar.gz - to - tarfile.tar.bz2
      • tarfile.tar.gz - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
      • tarfile.tar.bz2 - to - directory
      • tarfile.tar.bz2 - to - zipfile.zip
      • tarfile.tar.bz2 - to - tarfile.tar
      • tarfile.tar.bz2 - to - tarfile.tar.gz
      • tarfile.tar.bz2 - to - tarfile.tar.bz2
      • tarfile.tar.bz2 - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
URL files:
  • One-to-one file conversions:
    • id - to - textfile
    • id - to - textfile.gz
    • id - to - textfile.bz2
    • id - to - textfile.zip / textfile.tar / textfile.tar.gz / textfile.tar.bz2 (TypeError: One-to-many conversion)
    • textfileurl - to - textfile
    • textfileurl - to - textfile.gz
    • textfileurl - to - textfile.bz2
    • textfileurl.gz - to - textfile
    • textfileurl.gz - to - textfile.gz
    • textfileurl.gz - to - textfile.bz2
    • textfileurl.bz2 - to - textfile
    • textfileurl.bz2 - to - textfile.gz
    • textfileurl.bz2 - to - textfile.bz2
    • textfileurl / textfileurl.gz / textfileurl.bz2 - to - textfile.zip / textfile.tar / textfile.tar.gz / textfile.tar.bz2 (TypeError: One-to-many conversion)
  • Many-to-many files conversions:
    • Zipfiles:
      • zipfileurl.zip - to - directory
      • zipfileurl.zip - to - zipfile.zip
      • zipfileurl.zip - to - tarfile.tar
      • zipfileurl.zip - to - tarfile.tar.gz
      • zipfileurl.zip - to - tarfile.tar.bz2
      • zipfileurl.zip - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
    • Tarfiles:
      • tarfileurl.tar - to - directory
      • tarfileurl.tar - to - zipfile.zip
      • tarfileurl.tar - to - tarfile.tar
      • tarfileurl.tar - to - tarfile.tar.gz
      • tarfileurl.tar - to - tarfile.tar.bz2
      • tarfileurl.tar - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
      • tarfileurl.tar.gz - to - directory
      • tarfileurl.tar.gz - to - zipfile.zip
      • tarfileurl.tar.gz - to - tarfile.tar
      • tarfileurl.tar.gz - to - tarfile.tar.gz
      • tarfileurl.tar.gz - to - tarfile.tar.bz2
      • tarfileurl.tar.gz - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
      • tarfileurl.tar.bz2 - to - directory
      • tarfileurl.tar.bz2 - to - zipfile.zip
      • tarfileurl.tar.bz2 - to - tarfile.tar
      • tarfileurl.tar.bz2 - to - tarfile.tar.gz
      • tarfileurl.tar.bz2 - to - tarfile.tar.bz2
      • tarfileurl.tar.bz2 - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
class nmrstarlib.converter.Converter(file_generator)[source]

Converter class to convert NMR-STAR/CIF files from NMR-STAR/CIF to JSON or from JSON to NMR-STAR/CIF format.

__init__(file_generator)[source]

Converter initializer.

Parameters:file_generator (nmrstarlib.converter.Translator) –
convert()[source]

Convert file(s) from NMR-STAR/CIF format to JSON format or from JSON format to NMR-STAR/CIF format.

Returns:None
Return type:None
_many_to_many()[source]

Perform many-to-many files conversion.

Returns:None
Return type:None
_one_to_one()[source]

Perform one-to-one file conversion.

Returns:None
Return type:None
_to_dir(file_generator)[source]

Convert files to directory.

Returns:None
Return type:None
_to_zipfile(file_generator)[source]

Convert files to zip archive.

Returns:None
Return type:None
_to_tarfile(file_generator)[source]

Convert files to tar archive.

Returns:None
Return type:None
_to_bz2file(file_generator)[source]

Convert file to bz2-compressed file.

Returns:None
Return type:None
_to_gzipfile(file_generator)[source]

Convert file to gzip-compressed file.

Returns:None
Return type:None
_to_textfile(file_generator)[source]

Convert file to regular text file.

Returns:None
Return type:None
_output_path(inputpath, to_format, archive=False)[source]

Construct an output path string from an input path string.

Parameters:inputpath (str) – Input path string.
Returns:Output path string.
Return type:str
__weakref__

list of weak references to the object (if defined)

nmrstarlib.csviewer

This module provides the CSViewer class - Chemical Shifts Viewer that visualizes chemical shifts values.

class nmrstarlib.csviewer.CSViewer(from_path, amino_acids=None, atoms=None, amino_acids_and_atoms=None, filename=None, csview_format='svg', nmrstar_version='3')[source]

Chemical Shifts Viewer uses chem_shifts_by_residue() method to get chemical shifts organized by residue and visualizes chemical shifts values using the Graphviz (http://www.graphviz.org/) DOT Languge description.

__init__(from_path, amino_acids=None, atoms=None, amino_acids_and_atoms=None, filename=None, csview_format='svg', nmrstar_version='3')[source]

CSViewer initializer.

Parameters:
  • from_path (str) – Path to single NMR-STAR file or BMRB id.
  • amino_acids (list or tuple) – Sequence of amino acids three letter codes, e.g. ‘ALA’, ‘GLY’, ‘SER’, etc. Leave as None to include everything.
  • atoms (list or tuple) – Sequence of atom types, e.g. ‘CA’, ‘CB’, ‘HA’, etc. Leave as None to include everything.
  • amino_acids_and_atoms (dict) – Amino acid and its atoms key-value pairs.
  • filename (str) – Output filename chemical shifts graph to be saved.
  • csview_format (str) – svg, png, pdf. See http://www.graphviz.org/doc/info/output.html for all available formats.
  • nmrstar_version (str) – Version of NMR-STAR format to use for look up chemichal shifts loop.
Returns:

None

Return type:

None

csview(view=False)[source]

View chemical shift values organized by amino acid residue.

Parameters:view (True or False) – Open in default image viewer or save file in current working directory quietly.
Returns:None
Return type:None
__weakref__

list of weak references to the object (if defined)

nmrstarlib.noise

This module provides the NoiseGenerator class for adding noise values to Peak dimensions within a PeakList.

class nmrstarlib.noise.NoiseGenerator(parameters=None, distribution_name='normal', seed=None)[source]

Noise generator class.

__init__(parameters=None, distribution_name='normal', seed=None)[source]

Noise generator initializer.

Parameters:
  • parameters (dict) – Statistical distribution parameters per each peak list split.
  • distribution_name (str) – Name of the statistical distribution function.
__weakref__

list of weak references to the object (if defined)

generate(labels, split_idx)[source]

Generate peak-specific noise abstract method, must be reimplemented in a subclass.

Parameters:
  • labels (tuple) – Dimension labels of a peak.
  • split_idx (int) – Index specifying which peak list split parameters to use.
Returns:

List of noise values for dimensions ordered as they appear in a peak.

Return type:

list

nmrstarlib.plsimulator

This module provides interface classes necessary to create simulated peak list file.

class nmrstarlib.plsimulator.DimensionComponent(label, position)[source]

Dimensions component interface.

__init__(label, position)[source]

Dimension component.

Parameters:
  • label (str) – Label of a dimension.
  • position (int) – Position of dimensions within a peak according to sequence site position (-1, 0, or +1).
__weakref__

list of weak references to the object (if defined)

class nmrstarlib.plsimulator.DimensionGroup(label, position)[source]

Composite dimension group.

__init__(label, position)[source]

Dimension group.

Parameters:
  • label (str) – Label of a dimension.
  • position (int) – Position of dimensions within a peak according to sequence site position, (-1, 0, or +1).
class nmrstarlib.plsimulator.Dimension(label, position, assignment=None, chemshift=None)[source]

Concrete dimension.

__init__(label, position, assignment=None, chemshift=None)[source]

Concrete dimension intializer.

Parameters:
  • label (str) – Label of a dimension.
  • position (int) – Position of dimensions within a peak according to sequence site position, (-1, 0, or +1).
  • assignment (str) – Chemical shift assignment of a dimension.
  • chemshift (float) – Chemical shift value of a dimension.
class nmrstarlib.plsimulator.Peak(labels)[source]

Peak within a peak list.

__init__(labels)[source]

Peak initializer.

Parameters:labels (tuple) – Dimension labels of peak.
assignments_list

List of assignments per each dimension within a peak.

Returns:List of assignments.
Return type:list
chemshifts_list

List of chemical shift values per each dimensions within a peak.

Returns:List of chemical shifts.
Return type:list
apply_noise(noise_generator, split_idx, ndigits=6)[source]

Apply noise to dimensions within a peak.

Parameters:
  • noise_generator – Noise generator object.
  • split_idx (int) – Index specifying which peak list split parameters to use.
Returns:

None

Return type:

None

__weakref__

list of weak references to the object (if defined)

class nmrstarlib.plsimulator.PeakList(spectrum_name, labels, source, chain_idx)[source]

Peak list contains chemical shift values and assignment information for each peak.

__init__(spectrum_name, labels, source, chain_idx)[source]

Peak list initializer.

Parameters:
  • spectrum_name (str) – Spectrum name from which peak list will be simulated.
  • labels (list) – Sequence of labels as they appear in a peak.
  • source (str) – NMRStarFile source.
  • chain_idx (int) – NMRStarFile chain index.
_to_sparky()[source]

Save PeakList into Sparky-formatted string.

Returns:Peak list representation in Sparky format.
Return type:str
_to_autoassign()[source]

Save PeakList into AutoAssign-formatted string.

Returns:Peak list representation in AutoAssign format.
Return type:str
_to_json()[source]

Save PeakList into JSON string.

Returns:Peak list representation in JSON format.
Return type:str
write(filehandle, fileformat)[source]

Write PeakList data into file.

Parameters:
  • filehandle (io.TextIOWrapper) – file-like object.
  • fileformat (str) – Format to use to write data: sparky, autoassign, or json.
Returns:

None

Return type:

None

writestr(fileformat)[source]

Write PeakList data into string.

Parameters:fileformat (str) – Format to use to write data: sparky, autoassign, or json.
Returns:String representing the PeakList instance.
Return type:str
__weakref__

list of weak references to the object (if defined)

class nmrstarlib.plsimulator.SpinSystem[source]

Spin system - collection of related resonances associated with specific atoms in a molecule.

__init__()[source]

Spin system initializer.

__weakref__

list of weak references to the object (if defined)

class nmrstarlib.plsimulator.SequenceSite(residues)[source]

Sequence site.

__init__(residues)[source]

Sequence site initializer.

is_sequential()[source]

Check if residues that sequence site is composed of are in sequential order.

Returns:If sequence site is in valid sequential order (True) or not (False).
Return type:True or False
__weakref__

list of weak references to the object (if defined)

class nmrstarlib.plsimulator.PeakTemplate(dimensions)[source]

Peak templates defined as a list of concrete dimensions.

__init__(dimensions)[source]

Peak template initializer.

dimension_labels

List of dimension labels.

Returns:List of dimension labels of a peak template.
Return type:list
dimension_positions

List of dimension positions.

Returns:List of dimension positions of a peak template.
Return type:list
__weakref__

list of weak references to the object (if defined)

class nmrstarlib.plsimulator.PeakDescription(fraction, dimension_labels)[source]

Peak descriptions defined as list of general dimension groups.

__init__(fraction, dimension_labels)[source]

Peak description initializer.

Parameters:
  • fraction (float) – Describes expected number of peaks.
  • dimension_labels – List of dimension labels.
static create_dimension_groups(dimension_positions)[source]

Create list of dimension groups.

Parameters:dimension_positions (zip) – List of tuples describing dimension and its position within sequence site.
Returns:List of dimension groups.
Return type:list
__weakref__

list of weak references to the object (if defined)

class nmrstarlib.plsimulator.Spectrum(name, labels, min_spin_system_peaks, amino_acids_and_atoms=None)[source]

Spectrum object described as a list of general peak descriptions.

__init__(name, labels, min_spin_system_peaks, amino_acids_and_atoms=None)[source]

Spectrum initializer.

Parameters:
  • name (str) – Spectrum name.
  • labels – Sequence of dimension labels as they appear in a peak.
  • min_spin_system_peaks (int) – Minimum number of peaks per spin system.
peak_templates

Create a list of concrete peak templates from a list of general peak descriptions.

Returns:List of peak templates.
Return type:list
seq_site_length

Calculate length of a single sequence site based upon relative positions specified in peak descriptions.

Returns:Length of sequence site.
Return type:int
__weakref__

list of weak references to the object (if defined)

nmrstarlib.translator

This module provides the Translator abstract class and concrete classes: StarFileToStarFile for converting between NMR-STAR/CIF and JSONized NMR-STAR/CIF formats and StarFileToPeakList for converting NMR-STAR formatted file into simulated peak list file.

class nmrstarlib.translator.Translator(from_path, to_path, from_format=None, to_format=None)[source]

Translator abstract class.

__init__(from_path, to_path, from_format=None, to_format=None)[source]

Translator initializer.

Parameters:
  • from_path (str) – Path to input file(s).
  • to_path (str) – Path to output file(s).
  • from_format (str) – Input format.
  • to_format (str) – Output format.
__iter__()[source]

Abstract iterator must be implemented in a subclass.

__weakref__

list of weak references to the object (if defined)

class nmrstarlib.translator.StarFileToStarFile(from_path, to_path, from_format=None, to_format=None)[source]

Translator concrete class that can convert between NMR-STAR/CIF and JSONized NMR-STAR/CIF formats.

__init__(from_path, to_path, from_format=None, to_format=None)[source]

StarFileToStarFile translator initializer.

Parameters:
  • from_path (str) – Path to input file(s).
  • to_path (str) – Path to output file(s).
  • from_format (str) – Input format: nmrstar, cif, or json.
  • to_format (str) – Output format: nmrstar, cif, or json.
__iter__()[source]

Iterator that yields instances of StarFile instances.

Returns:instance of StarFile object instance.
Return type:StarFile
class nmrstarlib.translator.StarFileToPeakList(from_path, to_path, from_format, to_format, spectrum_name, plsplit=None, noise_generator=None, nmrstar_version='3')[source]

Translator concrete class that can convert NMR-STAR of JSONized NMR-STAR formatted file into peak list file.

__init__(from_path, to_path, from_format, to_format, spectrum_name, plsplit=None, noise_generator=None, nmrstar_version='3')[source]

StarFileToPeakList initializer.

Parameters:
  • from_path (str) – Path to input file(s).
  • to_path (str) – Path to output file(s).
  • from_format (str) – Input format: nmrstar or json.
  • to_format (str) – Output format: json or sparky.
  • spectrum_name (str) – Name of spectrum from which to simulate peak list.
  • plsplit (tuple) – How to split peak list in order to account for multiple sources of variance.
  • nmrstar_version (str) – Version of NMR-STAR format to use for look up chemical shifts loop.
  • noise_generator (NoiseGenerator) – Subclasses of NoiseGenerator object.
static create_spectrum(spectrum_name)[source]

Initialize spectrum and peak descriptions.

Parameters:spectrum_name (str) – Name of the spectrum from which peak list will be simulated.
Returns:Spectrum object.
Return type:Spectrum
static create_sequence_sites(chain, seq_site_length)[source]

Create sequence sites using sequence ids.

Parameters:
  • chain (dict) – Chain object that contains chemical shift values and assignment information.
  • seq_site_length (int) – Length of a single sequence site.
Returns:

List of sequence sites.

Return type:

list

static calculate_intervals(chunk_sizes)[source]

Calculate intervals for a given chunk sizes.

Parameters:chunk_sizes (list) – List of chunk sizes.
Returns:Tuple of intervals.
Return type:tuple
split_by_percent(spin_systems_list)[source]

Split list of spin systems by specified percentages.

Parameters:spin_systems_list (list) – List of spin systems.
Returns:List of spin systems divided into sub-lists corresponding to specified split percentages.
Return type:list
create_peaklist(spectrum, chain, chain_idx, source)[source]

Create peak list file.

Parameters:
  • spectrum (Spectrum) – Spectrum object instance.
  • chain (dict) – Chain object that contains chemical shift values and assignment information.
  • chain_idx (int) – Protein chain index.
  • source (str) – StarFile source.
Returns:

Peak list object.

Return type:

PeakList

__iter__()[source]

Iterator that yields instances of PeakList instances.

Returns:instance of PeakList object instance.
Return type:PeakList

nmrstarlib.fileio

This module provides routines for reading NMR-STAR and CIF formatted files from difference kinds of sources:

  • Single NMR-STAR or CIF formatted file on a local machine.
  • Directory containing multiple NMR-STAR or CIF formatted files.
  • Compressed zip/tar archive of NMR-STAR or CIF formatted files.
  • URL address of NMR-STAR or CIF formatted file.
  • BMRB ID of NMR-STAR or PDB ID of CIF formatted file.
nmrstarlib.fileio._generate_filenames(sources)[source]

Generate filenames.

Parameters:sources (tuple) – Sequence of strings representing path to file(s).
Returns:Path to file(s).
Return type:str
nmrstarlib.fileio._generate_handles(filenames)[source]

Open a sequence of filenames one at time producing file objects. The file is closed immediately when proceeding to the next iteration.

Parameters:filenames (generator) – Generator object that yields the path to each file, one at a time.
Returns:Filehandle to be processed into a StarFile instance.
nmrstarlib.fileio.read_files(*sources)[source]

Construct a generator that yields StarFile instances.

Parameters:sources – One or more strings representing path to file(s).
Returns:StarFile instance(s).
Return type:StarFile
class nmrstarlib.fileio.GenericFilePath(path)[source]

GenericFilePath class knows how to open local files or files over URL.

__init__(path)[source]

Initialize path.

Parameters:path (str) – String representing a path to local file(s) or valid URL address of file(s).
open()[source]

Generator that opens and yields filehandles using appropriate facilities: test if path represents a local file or file over URL, if file is compressed or not.

Returns:Filehandle to be processed into a StarFile instance.
static is_compressed(path)[source]

Test if path represents compressed file(s).

Parameters:path (str) – Path to file(s).
Returns:String specifying compression type if compressed, “” otherwise.
Return type:str
static is_url(path)[source]

Test if path represents a valid URL.

Parameters:path (str) – Path to file.
Returns:True if path is valid url string, False otherwise.
Return type:True or False
__weakref__

list of weak references to the object (if defined)