Skip to content

Commit

Permalink
Add option to name the RDFs
Browse files Browse the repository at this point in the history
  • Loading branch information
hmcezar committed Oct 5, 2023
1 parent 0be6e2e commit e684e84
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions utils/compute_rdf_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import matplotlib.pyplot as plt
import os
import sys
from glob import glob
import argparse
from tqdm import tqdm
Expand All @@ -25,6 +26,9 @@ def process_topology(topol_path):


def parse_masses(fname):
if not fname:
return None

masses = {}
with open(fname, "r") as f:
for line in f:
Expand All @@ -37,6 +41,7 @@ def compute_rdfs(
pdbdir,
agg_size,
selections,
name_selections,
center,
nbins,
rmax,
Expand All @@ -47,6 +52,7 @@ def compute_rdfs(
save_centered,
save_agg_only,
):
# initialize
rdfs = {}
for i in range(len(selections)):
rdfs[i] = np.zeros(nbins)
Expand Down Expand Up @@ -191,7 +197,7 @@ def compute_rdfs(
if not skip_rdfs:
# create selections for which RDFs will be computed
for i, sel_string in enumerate(selections):
if sel_string.strip().lower() in ["name w", "type w"]:
if sel_string.strip().lower() in ["name w", "type w", "name na", "type na", "name cl", "type cl"]:
at_sel = u.select_atoms(sel_string)
else:
at_sel = u.select_atoms(f"resid {resid} and " + sel_string)
Expand Down Expand Up @@ -227,7 +233,7 @@ def compute_rdfs(
for i, sel in enumerate(selections):
rdfs[i] = rdfs[i] / (shell_volumes * nsnaps)

plt.plot(mid_bin / 10.0, rdfs[i], linewidth=3, label=sel)
plt.plot(mid_bin / 10.0, rdfs[i], linewidth=3, label=name_selections[i])

np.savetxt(f"{agg_size}_" + sel.replace(" ", "_") + ".txt", rdfs[i])

Expand Down Expand Up @@ -320,6 +326,12 @@ def compute_rdfs(
nargs="+",
help='use quotes to specify the selections for the RDFs (e.g. "name C" "name TC5")',
)
parser.add_argument(
"--name-selections",
type=str,
nargs="+",
help='use quotes to specify the names of selections for the RDFs (e.g. "Phenyl 1" "Phenyl 2")',
)
parser.add_argument(
"--nbins",
type=int,
Expand Down Expand Up @@ -379,23 +391,26 @@ def compute_rdfs(

if args.principal_moments_rg and not args.masses:
raise AssertionError("--principal-moments-rg requires passing the masses")

if args.name_selections and (len(args.selections) != len(args.name_selections)):
raise AssertionError("the number of selections must be equal to the number of names")

topol = process_topology(args.topol)

if args.masses:
parsed_masses = parse_masses(args.masses)
else:
parsed_masses = None
# write options to file
with open("summary_compute_rdf_aggregates.txt", "w") as f:
f.write("Command: " + " ".join(sys.argv) + "\n")

compute_rdfs(
topol,
args.pdb_dir,
args.agg_size,
args.selections,
args.name_selections,
args.center,
args.nbins,
args.rmax,
parsed_masses,
parse_masses(args.masses),
args.do_not_compute_rdfs,
args.principal_moments_rg,
args.compute_pddf,
Expand Down

0 comments on commit e684e84

Please sign in to comment.