# `io`

Functions related to reading and writing data.

class pdb2pqr.io.DuplicateFilter

  Filter duplicate messages.

  __init__()

    Initialize a filter.

    Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.

  filter(record)

    Filter current record.

pdb2pqr.io.dump_apbs(output_pqr, output_path)

  Generate and dump APBS input files related to output_pqr.

  Parameters:

    - output_pqr (str) – path to PQR file used to generate APBS input file

    - output_path (str) – path for APBS input file output

pdb2pqr.io.get_definitions(aa_path='AA.xml', na_path='NA.xml', patch_path='PATCHES.xml')

  Load topology definition files.

  Parameters:

    - aa_path (str) – likely location of amino acid topology definitions

    - na_path (str) – likely location of nucleic acid topology definitions

    - patch_path (str) – likely location of patch topology definitions

  Returns:

    topology Definitions object.

  Return type:

    Definition

pdb2pqr.io.get_molecule(input_path)

  Get molecular structure information as a series of parsed lines.

  Parameters:

    input_path – structure file PDB ID or path

  Returns:

    (list of molecule records, Boolean indicating whether entry is CIF)

  Return type:

    ([str], bool)

  Raises:

    RuntimeError – problems with structure file

pdb2pqr.io.get_old_header(pdblist)

  Get old header from list of `pdb` objects.

  Parameters:

    pdblist ([]) – list of `pdb` block objects

  Returns:

    old header as string

  Return type:

    str

pdb2pqr.io.get_pdb_file(name)

  Obtain a PDB file.

  First check the path given on the command line - if that file is not available, obtain the file from the PDB webserver at http://www.rcsb.org/pdb/

  Todo

  This should be a context manager (to close the open file).

  Todo

  Remove hard-coded parameters.

  Parameters:

    name (str) – name of PDB file (path) or PDB ID

  Returns:

    file-like object containing PDB file

  Return type:

    file

pdb2pqr.io.print_biomolecule_atoms(atomlist, chainflag=False, pdbfile=False)

  Get PDB-format text lines for specified atoms.

  Parameters:

    - atomlist ([Atom]) – the list of atoms to include

    - chainflag (bool) – flag whether to print chainid or not

  Returns:

    list of strings, each representing an atom PDB line

  Return type:

    [str]

pdb2pqr.io.print_pqr_header(pdblist, atomlist, reslist, charge, force_field, ph_calc_method, ph, ffout, include_old_header=False)

  Print the header for the PQR file.

  Parameters:

    - pdblist ([str]) – list of lines from original PDB with header

    - atomlist ([Atom]) – a list of atoms that were unable to have charges assigned

    - reslist ([Residue]) – a list of residues with non-integral charges

    - charge (float) – the total charge on the biomolecule

    - force_field (str) – the forcefield name

    - ph_calc_method (str) – pKa calculation method

    - ph (float) – pH value, if any

    - ffout (str) – forcefield used for naming scheme

  Returns:

    the header for the PQR file

  Return type:

    str

pdb2pqr.io.print_pqr_header_cif(atomlist, reslist, charge, force_field, ph_calc_method, ph, ffout, include_old_header=False)

  Print the header for the PQR file in CIF format.

  Parameters:

    - atomlist ([Atom]) – a list of atoms that were unable to have charges assigned

    - reslist ([Residue]) – a list of residues with non-integral charges

    - charge (float) – the total charge on the biomolecule

    - force_field (str) – the forcefield name

    - ph_calc_method (str) – pKa calculation method

    - ph (float) – pH value, if any

    - ffout (str) – forcefield used for naming scheme

  Returns:

    the header for the PQR file

  Return type:

    str

pdb2pqr.io.read_dx(dx_file)

  Read DX-format volumetric information.

  The OpenDX file format is defined at <https://www.idvbook.com/wp-content/uploads/2010/12/opendx.pdf`.

  Note

  This function is not a general-format OpenDX file parser and makes many assumptions about the input data type, grid structure, etc.

  Todo

  This function should be moved into the APBS code base.

  Parameters:

    dx_file (file) – file object for DX file, ready for reading as text

  Returns:

    dictionary with data from DX file

  Return type:

    dict

  Raises:

    ValueError – on parsing error

pdb2pqr.io.read_pqr(pqr_file)

  Read PQR file.

  Parameters:

    pqr_file (file) – file object ready for reading as text

  Returns:

    list of atoms read from file

  Return type:

    [Atom]

pdb2pqr.io.read_qcd(qcd_file)

  Read QCD (UHDB QCARD format) file.

  Parameters:

    qcd_file (file) – file object ready for reading as text

  Returns:

    list of atoms read from file

  Return type:

    [Atom]

pdb2pqr.io.setup_logger(output_pqr, level='DEBUG')

  Setup the logger.

  Setup logger to output the log file to the same directory as PQR output.

  Parameters:

    - output_pqr (str) – path to PQR file

    - level (str) – logging level

pdb2pqr.io.test_dat_file(name)

  Test for the forcefield file with a few name permutations.

  Parameters:

    name (str) – the name of the dat file

  Returns:

    the path to the file

  Return type:

    Path

  Raises:

    FileNotFoundError – file not found

pdb2pqr.io.test_for_file(name, type_)

  Test for the existence of a file with a few name permutations.

  Parameters:

    - name (str) – name of file

    - type (str) – type of file

  Returns:

    path to file

  Raises:

    FileNotFoundError – if file not found

  Return type:

    Path

pdb2pqr.io.test_names_file(name)

  Test for the .names file that contains the XML mapping.

  Parameters:

    name (str) – the name of the forcefield

  Returns:

    the path to the file

  Return type:

    Path

  Raises:

    FileNotFoundError – file not found

pdb2pqr.io.test_xml_file(name)

  Test for the XML file with a few name permutations.

  Parameters:

    name (str) – the name of the dat file

  Returns:

    the path to the file

  Return type:

    Path

  Raises:

    FileNotFoundError – file not found

pdb2pqr.io.write_cube(cube_file, data_dict, atom_list, comment='CPMD CUBE FILE.')

  Write a Cube-format data file.

  Cube file format is defined at <https://docs.chemaxon.com/display/Gaussian_Cube_format.html>.

  Todo

  This function should be moved into the APBS code base.

  Parameters:

    - cube_file (file) – file object ready for writing text data

    - data_dict (dict) – dictionary of volumetric data as produced by `read_dx()`

    - comment (str) – comment for Cube file