-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodeMatch.py
More file actions
123 lines (105 loc) · 5.57 KB
/
modeMatch.py
File metadata and controls
123 lines (105 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
This file is part of CDIO Tools: https://github.com/donaldlab/CASP16
Copyright (C) 2025 Bruce Donald Lab, Duke University
CDIO Tools is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License version 2 as published by the Free
Software Foundation.
You should have received a copy of the GNU General Public License along with
CDIO Tools. If not, see <http://www.gnu.org/licenses/>.
Our lab's software relies on grants for its development, and since visibility
in the scientific literature is essential for our success, we ask that users of
CDIO Tools cite our papers. See the CITATION.cff and README.md documents in
this distribution for more information.
Contact Info:
Bruce Donald
Duke University
Department of Computer Science
Levine Science Research Center (LSRC)
Durham
NC 27708-0129
USA
e-mail: www.cs.duke.edu/brd/
<signature of Bruce Donald>, Sept 24, 2025
Bruce Donald, Professor of Computer Science
"""
from scipy.spatial.transform import Rotation as R
from argparse import ArgumentParser
from pathlib import Path
import cdiotools.ensembles
import cdiotools.rotation
import cdiotools.cdios
import csv
import numpy as np
def main():
argParser = ArgumentParser()
argParser.add_argument("--preddir", type=str, required=True)
argParser.add_argument("--spreads", default=[-(2**n) for n in [5]], type=int, nargs='+', required=False)
argParser.add_argument("--gridfn", default='grids/quatsForDoS.txt', type=str, required=False)
argParser.add_argument("--refZ", default='pdbs/1Q2N_Zdomain.pdb', type=str, required=False)
argParser.add_argument("--refchainZ", default='A', type=str, required=False)
argParser.add_argument("--refchainC", default='A', type=str, required=False)
argParser.add_argument("--ranges", default=[24, 37, 53, 68, 95, 108, 112, 126], type=int, nargs=8, required=False)
argParser.add_argument("--cdiodir", default='cdios', type=str, required=False)
argParser.add_argument("--modesfn", default='solutionMixtureModes_hugegrid.qua.csv', type=str, required=False)
argParser.add_argument("--nproc", default=1, type=int, required=False)
argParser.add_argument("--nowrite", default=False, action='store_true')
argParser.add_argument("--debug", default=False, action='store_true')
args = argParser.parse_args()
cdioPath = cdiotools.cdios.setUpCDIOPath(args.cdiodir, args.nowrite)
refRangesZAdj, rangesZ, rangesC = cdiotools.ensembles.setUpRefRanges(args.refZ, args.ranges, args.refchainZ, args.debug)
grid = cdiotools.rotation.readQuats(args.gridfn)
modesByAlpha = {}
with open(args.modesfn, 'r', newline='') as modesfile:
reader = csv.DictReader(modesfile)
for row in reader:
def colToFloat(colname):
return float(row[colname])
modesByAlpha[row['alpha']] = np.array([colToFloat(col) for col in ['q1', 'q2', 'q3', 'q4']])
soldiscsByName = cdiotools.cdios.discretizeByAlpha(grid, 101, 2)
# Compute the rotation between the modes of each ground-truth
# Bingham solution and each (kernelized) predictor ensemble.
predOntoSolInCDIOFrame = {} # By sol, by subdir, by spread
for spread in args.spreads:
predOntoSolInCDIOFrame[spread] = {}
for subdir in Path(args.preddir).glob("*.cleaned"):
def cdioNamePred(subdir, spread, _):
return f'cdio_{subdir.name}_{spread}.txt'
def subdirToCDIO(subdir, spread, _):
return cdiotools.ensembles.findPredictorCDIO(subdir, grid, spread, rangesZ, rangesC, refRangesZAdj, debug=args.debug)
predictor_densities = cdiotools.cdios.findAndWriteCDIO(subdirToCDIO, subdir, spread, None, cdioPath, cdioNamePred)
mode_grid_point, _ = cdiotools.cdios.getModeFromCDIO(grid, predictor_densities)
rotSolModes = {alpha: R.from_quat(cdiotools.rotation.toScalarLast(mode)) for alpha, mode in modesByAlpha.items()}
rotPredMode = R.from_quat(cdiotools.rotation.toScalarLast(mode_grid_point))
predOntoSolInCDIOFrame[spread][subdir] = {alpha: r * rotPredMode.inv() for alpha, r in rotSolModes.items()}
with open(f'angDistByAlpha_{spread}.csv', 'w', newline='') as angdistfile:
angdistwriter = csv.writer(angdistfile)
alphas = list(modesByAlpha.keys())
angdistwriter.writerow(['ensemble'] + alphas)
for subdir in Path(args.preddir).glob("*.cleaned"):
angdistwriter.writerow([subdir.name] + [predOntoSolInCDIOFrame[spread][subdir][alpha].magnitude() for alpha in alphas])
# Functions giving file and row names related to predictor-ensemble
# CDIOS, as well as a function wrapper that partially applies
# appropriate arguments to findPredictorCDIO
def cdioNamePred(subdir, spread, alpha):
return f'cdio_{subdir.name}_{spread}_rotsol{alpha}.txt'
def subdirToCDIO(subdir, spread, alpha):
return cdiotools.ensembles.findPredictorCDIO(subdir, grid, spread, rangesZ, rangesC, refRangesZAdj, rotation=predOntoSolInCDIOFrame[spread][subdir][alpha], debug=args.debug)
def rowNamePred(subdir):
return subdir.name
dirpath = Path(args.preddir)
paramList = [subdir for subdir in dirpath.glob("*.cleaned")]
cdiotools.cdios.writeIntegralDiffs(
soldiscsByName,
grid,
args.spreads,
dirpath.name + '_rot',
cdioNamePred,
subdirToCDIO,
rowNamePred,
paramList,
args.nproc,
cdioPath,
args.nowrite
)
if __name__ == '__main__':
main()