Skip to content

Commit

Permalink
Merge pull request #249 from diogomart/clean_import_os
Browse files Browse the repository at this point in the history
uniformize os.linesep as eol (no pathlib.os in Python 3.13)
  • Loading branch information
diogomart authored Nov 17, 2024
2 parents aec2e9e + 506bb59 commit aa8d4df
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 106 deletions.
2 changes: 0 additions & 2 deletions meeko/analysis/fingerprint_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# Meeko
#

import os

import numpy as np
try:
import pandas as pd
Expand Down
1 change: 0 additions & 1 deletion meeko/analysis/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Meeko - Interactions
#

import os
from abc import ABC, abstractmethod

import numpy as np
Expand Down
5 changes: 0 additions & 5 deletions meeko/bondtyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
# Meeko bond typer
#

import os
import sys
from collections import defaultdict
from operator import itemgetter


class BondTyperLegacy:

Expand Down
5 changes: 3 additions & 2 deletions meeko/cli/mk_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gzip
import pathlib
import sys
from os import linesep as eol
import warnings
import copy
import numpy as np
Expand Down Expand Up @@ -143,10 +144,10 @@ def main():
iter_pose._positions = np.array([pdbqt_mol._positions[pose_id]])
iter_pose._pose_data['n_poses'] = 1 # Update the number of poses to reflect the reduction
iter_pose._current_pose = 0 # Reset to the first (and only) pose
pdb_string += "MODEL " + f"{model_nr:8}" + pathlib.os.linesep
pdb_string += "MODEL " + f"{model_nr:8}" + eol
pol_copy = copy.deepcopy(polymer)
pdb_string += export_pdb_updated_flexres(pol_copy, iter_pose)
pdb_string += "ENDMDL" + pathlib.os.linesep
pdb_string += "ENDMDL" + eol
if write_pdb is None:
fn = pathlib.Path(filename).with_suffix("").name + f"{suffix}.pdb"
else:
Expand Down
3 changes: 2 additions & 1 deletion meeko/cli/mk_prepare_ligand.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime
import io
import os
from os import linesep as eol
import sys
import json
import tarfile
Expand Down Expand Up @@ -333,7 +334,7 @@ def cmd_lineparser():
sys.exit(2)
is_covalent = num_required_covalent_args == 3
if is_covalent and not _has_prody:
msg = "Covalent docking requires Prody which is not installed." + os.linesep
msg = "Covalent docking requires Prody which is not installed." + eol
msg += "Installable from PyPI (pip install prody) or conda-forge (micromamba install prody)"
print(_prody_import_error, file=sys.stderr)
print(msg)
Expand Down
34 changes: 17 additions & 17 deletions meeko/cli/mk_prepare_receptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import argparse
import json
import math
from os import linesep as os_linesep
from os import linesep as eol
import pathlib
import sys

Expand Down Expand Up @@ -265,19 +265,19 @@ def get_args():
if args.read_pdb is None and args.read_with_prody is None:
parser.print_help()
msg = "Need input filename: use either -i/--read_with_prody or --read_pdb"
print(os_linesep + msg)
print(eol + msg)
sys.exit(2)

if args.read_pdb is not None and args.read_with_prody is not None:
msg = "Can't use both -i/--read_with_prody and --read_pdb"
print(os_linesep + msg, file=sys.stderr)
print(eol + msg, file=sys.stderr)
sys.exit(2)

if args.write_gpf is not None and args.write_pdbqt is None:
# there's a few of places that assume this condition has been checked
msg = "--write_gpf requires --write_pdbqt because autogrid expects"
msg += " the GPF file to point to the PDBQT file."
print(os_linesep + msg)
print(eol + msg)
sys.exit(2)

skip_gpf = args.write_gpf is None and args.write_vina_box is None
Expand Down Expand Up @@ -397,7 +397,7 @@ def main():
print(
"Command line error: repeated resname %s passed to --reactive_resname"
% resname
+ os_linesep,
+ eol,
file=sys.stderr,
)
sys.exit(2)
Expand All @@ -414,7 +414,7 @@ def main():
print(
"Command line error: repeated resid %s passed to --reactive_name_specific"
% res_id
+ os_linesep,
+ eol,
file=sys.stderr,
)
sys.exit(2)
Expand All @@ -439,7 +439,7 @@ def main():
# Evaluate compatibility with other options
if len(reactive_flexres) != 1 and args.box_center_off_reactive_res:
msg = (
"--box_center_off_reactive_res can be used only with one reactive" + os_linesep
"--box_center_off_reactive_res can be used only with one reactive" + eol
)
msg += "residue, but %d reactive residues are set" % len(reactive_flexres_name)
print("Command line error:" + msg, file=sys.stderr)
Expand Down Expand Up @@ -539,7 +539,7 @@ def main():
reactive_flexres_name[res_id] = reactive_atom[input_resname]
else:
print("no default reactive name for %s, " % input_resname)
print("use --reactive_name or --reactive_name_specific" + os_linesep)
print("use --reactive_name or --reactive_name_specific" + eol)
sys.exit(2)

# Print nonreactive and reactive flexible residues specs
Expand Down Expand Up @@ -680,12 +680,12 @@ def warn_flexres_outside_box(polymer, box_center, box_size):
continue
if gridbox.is_point_outside_box(atom.coord, box_center, box_size, spacing=1.0):
print(
"WARNING: Flexible residue outside box." + os_linesep,
"WARNING: Flexible residue outside box." + eol,
file=sys.stderr,
)
print(
"WARNING: Strongly recommended to use a box that encompasses flexible residues."
+ os_linesep,
+ eol,
file=sys.stderr,
)
break # only need to warn once
Expand Down Expand Up @@ -850,7 +850,7 @@ def warn_flexres_outside_box(polymer, box_center, box_size):
any_lig_reac_types.append(reactive_typer.get_reactive_atype(t, order))

rec_reac_types = []
for line in all_flex_pdbqt.split(os_linesep):
for line in all_flex_pdbqt.split(eol):
if line.startswith("ATOM") or line.startswith("HETATM"):
atype = line[77:].strip()
basetype, _ = reactive_typer.get_basetype_and_order(atype)
Expand All @@ -869,7 +869,7 @@ def warn_flexres_outside_box(polymer, box_center, box_size):
if len(collisions) > 0:
collision_str = ""
for t1, t2 in collisions:
collision_str += "%3s %3s" % (t1, t2) + os_linesep
collision_str += "%3s %3s" % (t1, t2) + eol
collision_fn = str(outpath.with_suffix(".atype_collisions"))
written_files_log["filename"].append(collision_fn)
written_files_log["description"].append(
Expand All @@ -887,19 +887,19 @@ def warn_flexres_outside_box(polymer, box_center, box_size):
all_types = []
for basetype, reactypes in derivtypes.items():
all_types.append(basetype)
map_block += "map %s.%s.map" % (map_prefix, basetype) + os_linesep
map_block += "map %s.%s.map" % (map_prefix, basetype) + eol
for reactype in reactypes:
all_types.append(reactype)
map_block += "map %s.%s.map" % (map_prefix, basetype) + os_linesep
config = "ligand_types " + " ".join(all_types) + os_linesep
config += "fld %s.maps.fld" % map_prefix + os_linesep
map_block += "map %s.%s.map" % (map_prefix, basetype) + eol
config = "ligand_types " + " ".join(all_types) + eol
config += "fld %s.maps.fld" % map_prefix + eol
config += map_block

# in modpairs (dict): types are keys, parameters are values
# now we will write a configuration file with nbp keywords
# that AD-GPU reads using the --import_dpf flag
# nbp stands for "non-bonded potential" or "non-bonded pairwise"
line = "intnbp_r_eps %8.6f %8.6f %3d %3d %4s %4s" + os_linesep
line = "intnbp_r_eps %8.6f %8.6f %3d %3d %4s %4s" + eol
nbp_count = 0
for (t1, t2), param in modpairs.items():
config += line % (param["r_eq"], param["eps"], param["n"], param["m"], t1, t2)
Expand Down
32 changes: 16 additions & 16 deletions meeko/gridbox.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os import linesep as os_linesep
from os import linesep as eol
import pathlib
import numpy as np

Expand Down Expand Up @@ -82,7 +82,7 @@ def box_to_pdb_string(box_center, npts, spacing=0.375):
res = "BOX"
chain = "X"
pdb_out = ""
line = "ATOM %5d %4s %3s %1s%4d %8.3f%8.3f%8.3f 1.00 10.00 %1s" + os_linesep
line = "ATOM %5d %4s %3s %1s%4d %8.3f%8.3f%8.3f 1.00 10.00 %1s" + eol
for idx in range(len(corners)):
x = corners[idx][0]
y = corners[idx][1]
Expand All @@ -93,18 +93,18 @@ def box_to_pdb_string(box_center, npts, spacing=0.375):
# center
pdb_out += line % (count+1, "Xe", res, chain, idx+1, center_x, center_y, center_z, "Xe")

pdb_out += "CONECT 1 2" + os_linesep
pdb_out += "CONECT 1 4" + os_linesep
pdb_out += "CONECT 1 5" + os_linesep
pdb_out += "CONECT 2 3" + os_linesep
pdb_out += "CONECT 2 6" + os_linesep
pdb_out += "CONECT 3 4" + os_linesep
pdb_out += "CONECT 3 7" + os_linesep
pdb_out += "CONECT 4 8" + os_linesep
pdb_out += "CONECT 5 6" + os_linesep
pdb_out += "CONECT 5 8" + os_linesep
pdb_out += "CONECT 6 7" + os_linesep
pdb_out += "CONECT 7 8" + os_linesep
pdb_out += "CONECT 1 2" + eol
pdb_out += "CONECT 1 4" + eol
pdb_out += "CONECT 1 5" + eol
pdb_out += "CONECT 2 3" + eol
pdb_out += "CONECT 2 6" + eol
pdb_out += "CONECT 3 4" + eol
pdb_out += "CONECT 3 7" + eol
pdb_out += "CONECT 4 8" + eol
pdb_out += "CONECT 5 6" + eol
pdb_out += "CONECT 5 8" + eol
pdb_out += "CONECT 6 7" + eol
pdb_out += "CONECT 7 8" + eol
return pdb_out

def is_point_outside_box(point, center, npts, spacing=0.375):
Expand Down Expand Up @@ -156,5 +156,5 @@ def box_to_vina_string(gridcenter, gridsizes):
sizes_str = "\n".join([f"size_{d} = {gridsizes[i]:.3f}" for i, d in enumerate(dims)])
return centers_str + "\n" + sizes_str

boron_silicon_atompar = "atom_par Si 4.10 0.200 35.8235 -0.00143 0.0 0.0 0 -1 -1 6" + os_linesep
boron_silicon_atompar += "atom_par B 3.84 0.155 29.6478 -0.00152 0.0 0.0 0 -1 -1 0" + os_linesep
boron_silicon_atompar = "atom_par Si 4.10 0.200 35.8235 -0.00143 0.0 0.0 0 -1 -1 6" + eol
boron_silicon_atompar += "atom_par B 3.84 0.155 29.6478 -0.00152 0.0 0.0 0 -1 -1 0" + eol
Loading

0 comments on commit aa8d4df

Please sign in to comment.