Skip to content

Commit

Permalink
Merge pull request #315 from mimminou/master
Browse files Browse the repository at this point in the history
Eliminated need to write to temporary file in disk
  • Loading branch information
sobolevnrm authored May 9, 2022
2 parents ed782e5 + f47407f commit 43f40f9
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions pdb2pqr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import argparse
import sys
from collections import OrderedDict
from tempfile import NamedTemporaryFile
from io import StringIO
from pathlib import Path
import propka.lib
import propka.output as pk_out
Expand All @@ -27,7 +27,6 @@
from .utilities import noninteger_charge
from .config import VERSION, TITLE_STR, CITATIONS, FORCE_FIELDS
from .config import REPAIR_LIMIT
import os


_LOGGER = logging.getLogger(f"PDB2PQR{VERSION}")
Expand Down Expand Up @@ -506,21 +505,19 @@ def run_propka(args, biomolecule):
pKa information from PROPKA)
:rtype: (list, str)
"""
# TODO - eliminate need to write temporary file

lines = io.print_biomolecule_atoms(
atomlist=biomolecule.atoms, chainflag=args.keep_chain, pdbfile=True
)

pdb_path = NamedTemporaryFile(suffix=".pdb", delete=True).name
with open(pdb_path, "w") as fpdb:
for line in lines:
fpdb.write(line)
with StringIO() as fpdb:
fpdb.writelines(lines)
parameters = pk_in.read_parameter_file(args.parameters, Parameters())
molecule = MolecularContainer(parameters, args)
# needs a mock name with .pdb extension to work with stream data, hence the "input.pdb"
molecule = pk_in.read_molecule_file("input.pdb", molecule, fpdb)

parameters = pk_in.read_parameter_file(args.parameters, Parameters())
molecule = MolecularContainer(parameters, args)
molecule = pk_in.read_molecule_file(pdb_path, molecule)

os.remove(pdb_path)

molecule.calculate_pka()

Expand Down

0 comments on commit 43f40f9

Please sign in to comment.