Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

import pytest 

import os 

import subprocess as sb 

import sys 

sys.path.insert(1, '../') 

 

ncpus = 8 

 

# run coverage.sh to generate coverage 

 

def runTest(path, ncpus, results): 

os.system("rm -f {0}/*out".format(path)) 

results_lines = results.split('\n')[1:-1] 

sb.Popen("cd {0}; " 

"sed -i 's/ncpus .*/ncpus = {1}/' parameters.dat; " 

"coverage erase; " 

"coverage run ../../../pypka.py parameters.dat".format(path, ncpus), shell=True).wait() 

checkOutput('{0}/pKas.out'.format(path), results_lines) 

 

def checkOutput(filename, results_lines): 

with open(filename) as f: 

c = -1 

for line in f: 

c += 1 

line = line.strip() 

assert line == results_lines[c] 

assert c + 1 == len(results_lines) 

 

def checkAPIResult(pKa, results): 

i = -1 

for site in pKa: 

result = '{0} {1} {2}'.format(site, pKa[site], pKa.getProtState(site, 7)) 

i += 1 

assert result == results[i] 

assert i + 1 == len(results) 

 

class TestCLI(object): 

def test_cli_ktp_gro(self): 

path = "ktp/ktp_gro" 

results = """ 

1 NTR 7.89621829987 

1 TYR 9.88696575165 

2 CTR 3.12329292297 

""" 

runTest(path, ncpus, results) 

 

def test_cli_ktp_pdb_allsites(self): 

path = "ktp/ktp_pdb_allsites" 

results = """ 

1 NTR 7.900203228 

1 TYR 9.77924633026 

2 CTR 3.30362272263 

""" 

runTest(path, ncpus, results) 

 

def test_cli_ktp_pdb_allsites_noclean(self): 

path = "ktp/ktp_pdb_allsites_noclean" 

results = """ 

1 NTR 7.89621829987 

1 TYR 9.88696575165 

2 CTR 3.12329292297 

""" 

runTest(path, ncpus, results) 

 

def test_cli_ktp_pdb_onlytermini(self): 

path = 'ktp/ktp_pdb_onlytermini' 

results = """ 

1 NTR 7.904296875 

2 CTR 3.29493141174 

""" 

runTest(path, ncpus, results) 

 

def test_cli_ktp_pdb_onlytermini_noclean(self): 

path = 'ktp/ktp_pdb_onlytermini_noclean' 

results = """ 

1 NTR 8.17041015625 

2 CTR 3.38864183426 

""" 

runTest(path, ncpus, results) 

 

def test_cli_lyso_gro(self): 

path = "lyso/lyso_gro" 

results = """ 

1 NTR 7.63068819046 

18 ASP 3.14008665085 

35 GLU 4.66894435883 

48 ASP 2.96325278282 

66 ASP 3.25400090218 

129 CTR 2.35684490204 

""" 

runTest(path, ncpus, results) 

 

def test_cli_lyso_pdb_sites(self): 

path = "lyso/lyso_pdb_sites" 

results = """ 

1 NTR 7.50067424774 

18 ASP 3.16751217842 

35 GLU 4.61393737793 

48 ASP 2.26052093506 

66 ASP 1.87332427502 

129 CTR 2.30435156822 

""" 

runTest(path, ncpus, results) 

 

def test_cli_lyso_pdb_sites_noclean(self): 

path = "lyso/lyso_pdb_sites_noclean" 

results = """ 

1 NTR 7.39441871643 

18 ASP 2.78099513054 

35 GLU 4.27633476257 

48 ASP 2.65356683731 

66 ASP 3.01925420761 

129 CTR 1.94424641132 

""" 

runTest(path, ncpus, results) 

 

def test_cli_lyso_pdb_all(self): 

path = "lyso/lyso_pdb_all" 

results = """ 

1 NTR 7.38174772263 

1 LYS 10.3868246078 

7 GLU 2.88459134102 

13 LYS 100.0 

15 HIS 5.86267566681 

18 ASP 2.69885849953 

20 TYR 9.90721607208 

23 TYR 9.38904476166 

24 SER 100.0 

33 LYS 10.5100259781 

35 GLU 4.17546081543 

36 SER 100.0 

40 THR 100.0 

43 THR 100.0 

47 THR 100.0 

48 ASP 1.86072945595 

50 SER 100.0 

51 THR 100.0 

52 ASP 2.15181279182 

53 TYR 10.7421417236 

60 SER 100.0 

66 ASP 2.34874129295 

69 THR 100.0 

72 SER 100.0 

81 SER 100.0 

85 SER 100.0 

86 SER 100.0 

87 ASP 2.05946564674 

89 THR 100.0 

91 SER 100.0 

96 LYS 100.0 

97 LYS 100.0 

100 SER 100.0 

101 ASP 3.31438612938 

116 LYS 10.2509069443 

118 THR 100.0 

119 ASP 2.39909434319 

129 CTR 1.69917798042 

""" 

runTest(path, ncpus, results) 

 

def test_cli_lyso_pdb_all_noclean(self): 

path = "lyso/lyso_pdb_all_noclean" 

results = """ 

1 NTR 7.38174772263 

1 LYS 10.3868246078 

7 GLU 2.88459134102 

13 LYS 100.0 

15 HIS 5.86267566681 

18 ASP 2.69885849953 

20 TYR 9.90721607208 

23 TYR 9.38904476166 

24 SER 100.0 

33 LYS 10.5100259781 

35 GLU 4.17546081543 

36 SER 100.0 

40 THR 100.0 

43 THR 100.0 

47 THR 100.0 

48 ASP 1.86072945595 

50 SER 100.0 

51 THR 100.0 

52 ASP 2.15181279182 

53 TYR 10.7421417236 

60 SER 100.0 

66 ASP 2.34874129295 

69 THR 100.0 

72 SER 100.0 

81 SER 100.0 

85 SER 100.0 

86 SER 100.0 

87 ASP 2.05946564674 

89 THR 100.0 

91 SER 100.0 

96 LYS 100.0 

97 LYS 100.0 

100 SER 100.0 

101 ASP 3.31438612938 

116 LYS 10.2509069443 

118 THR 100.0 

119 ASP 2.39909434319 

129 CTR 1.69917798042 

""" 

runTest(path, ncpus, results) 

 

def test_cli_pHLIP_gro(self): 

path = "pHLIP/pHLIP_gro" 

results = """ 

769 NTR 11.0565090179 

770 CYS 100.0 

771 GLU 4.03883981705 

782 ASP 100.0 

793 ASP 100.0 

799 ASP 1.80626475811 

801 ASP 0.836304783821 

802 GLU 3.98396849632 

804 CTR 3.63486742973 

""" 

runTest(path, ncpus, results) 

 

def test_cli_pHLIP_pdb_all(self): 

path = "pHLIP/pHLIP_pdb_all" 

results = """ 

769 NTR 11.2083435059 

770 CYS 24.2029476166 

771 GLU 4.00404262543 

776 TYR 18.7731571198 

780 TYR 24.3460330963 

782 ASP 100.0 

786 THR 100.0 

787 THR 100.0 

793 ASP 22.6629772186 

799 ASP 0.369246691465 

801 ASP 1.48556101322 

802 GLU 3.96952009201 

804 CTR 4.29328298569 

""" 

runTest(path, ncpus, results) 

 

 

class TestAPI(object): 

def test_api_ktp_gro(self): 

from pypka import Titration 

os.system('rm -f LOG* *out *gro *pdb *pqr *crg *sites cent contributions interactions.dat pkint') 

results = """ 

NTR 7.89621829987 ('undefined', 0.8873165161846842) 

1 9.88696575165 ('protonated', 0.9987043991888108) 

CTR 3.12329292297 ('deprotonated', 0.00013281136488231348) 

""" 

results = results.split('\n')[1:-1] 

parameters = { 

'structure' : 'ktp/ktp_gro/TMP.gro', # MANDATORY 

'epsin' : 2, 

'ionicstr' : 0.1, 

'pbc_dimensions': 0, 

'temp' : 310, 

'grid_fill' : 0.8, # FUTURE VERSION 

'ncpus' : ncpus, 

'pH' : '-5,15', 

'pHstep' : 0.2, 

'logfile' : 'LOGFILE', 

'scaleM' : 4, 

'scaleP' : 1, 

'gsize' : 81, 

'convergence' : 0.01, 

'nlit' : 500, 

'cutoff' : -1, 

'relfac' : 0.0, 

'output' : 'pKas.out' 

} 

sites = {'A': ('1N', '1', '2C')} 

pKa = Titration(parameters, sites=sites) 

checkAPIResult(pKa, results) 

 

def test_api_ktp_pdb_allsites_clean(self): 

from pypka import Titration 

os.system('rm -f *out *gro *pdb *pqr *crg *sites cent contributions interactions.dat pkint') 

results = """ 

NTR 7.90208864212 ('undefined', 0.888660962962448) 

1 9.78845977783 ('protonated', 0.9983750726401587) 

CTR 3.3024392128 ('deprotonated', 0.00020060977015866723) 

""" 

results = results.split('\n')[1:-1] 

parameters = { 

'structure' : 'ktp/ktp_pdb_allsites/ktp.pdb', 

'clean_pdb' : 'yes', 

'epsin' : 2, 

'ionicstr' : 0.1, 

'pbc_dimensions': 0, 

'temp' : 310, 

'grid_fill' : 0.8, 

'ncpus' : ncpus, 

'pH' : '0,15', 

'pHstep' : 0.2, 

'logfile' : 'LOGFILE', 

'scaleM' : 4, 

'scaleP' : 1, 

'gsize' : 81, 

'convergence' : 0.01, 

'nlit' : 300, 

'cutoff' : -1, 

'relfac' : 0.0, 

'output' : 'pKas.out' 

} 

sites = 'all' 

pKa = Titration(parameters, sites=sites) 

checkAPIResult(pKa, results) 

 

def test_api_ktp_pdb_allsites_noclean(self): 

from pypka import Titration 

os.system('rm -rf LOG* *out *gro *pdb *pqr *crg *sites ' 

'cent contributions interactions.dat pkint LOG* __pycache__ *pyc') 

results = """ 

NTR 7.89621829987 ('undefined', 0.8873165161846842) 

1 9.88696575165 ('protonated', 0.9987043991888108) 

CTR 3.12329292297 ('deprotonated', 0.00013281136488231348) 

""" 

results = results.split('\n')[1:-1] 

parameters = { 

'structure' : 'ktp/ktp_pdb_allsites_noclean/ktp_noclean.pdb', # MANDATORY 

'clean_pdb' : 'no', 

'epsin' : 2, 

'ionicstr' : 0.1, 

'pbc_dimensions': 0, 

'temp' : 310, 

'grid_fill' : 0.8, # FUTURE VERSION 

'ncpus' : ncpus, 

'pH' : '-5,15', 

'pHstep' : 0.2, 

'logfile' : 'LOGFILE', 

'scaleM' : 4, 

'scaleP' : 1, 

'gsize' : 81, 

'convergence' : 0.01, 

'nlit' : 500, 

'cutoff' : -1, 

'relfac' : 0.0, 

'output' : 'pKas.out' 

} 

sites = 'all' 

pKa = Titration(parameters, sites=sites) 

checkAPIResult(pKa, results) 

 

def test_api_ktp_pdb_onlytermini(self): 

from pypka import Titration 

os.system('rm -rf LOG* *out *gro *pdb *pqr *crg *sites cent ' 

'contributions interactions.dat pkint LOG* __pycache__ *pyc') 

results = """ 

NTR 7.904296875 ('undefined', 0.8891630578319204) 

CTR 3.29493141174 ('deprotonated', 0.0001971722409805938) 

""" 

results = results.split('\n')[1:-1] 

parameters = { 

'structure' : 'ktp/ktp_pdb_onlytermini/ktp.pdb', # MANDATORY  

'clean_pdb' : 'yes', 

'epsin' : 2, 

'ionicstr' : 0.1, 

'pbc_dimensions': 0, 

'temp' : 310, 

'grid_fill' : 0.8, # FUTURE VERSION 

'ncpus' : ncpus, 

'pH' : '0,15', 

'pHstep' : 0.25, 

'logfile' : 'LOGFILE', 

'scaleM' : 4, 

'scaleP' : 1, 

'gsize' : 81, 

'convergence' : 0.01, 

'nlit' : 300, 

'cutoff' : -1, 

'relfac' : 0.0, 

'output' : 'pKas.out' 

} 

sites = {'A': ('1N', '2C')} 

pKa = Titration(parameters, sites=sites) 

checkAPIResult(pKa, results) 

 

def test_api_ktp_pdb_onlytermini_noclean(self): 

from pypka import Titration 

os.system('rm -rf LOG* *out *gro *pdb *pqr *crg *sites cent ' 

'contributions interactions.dat pkint LOG* __pycache__ *pyc') 

results = """ 

NTR 8.17041015625 ('protonated', 0.9367291213385088) 

CTR 3.38864183426 ('deprotonated', 0.00024464456585429595) 

""" 

results = results.split('\n')[1:-1] 

parameters = { 

'structure' : 'ktp/ktp_pdb_onlytermini_noclean/ktp_noclean.pdb', # MANDATORY  

'clean_pdb' : 'no', 

'epsin' : 2, 

'ionicstr' : 0.1, 

'pbc_dimensions': 0, 

'temp' : 310, 

'grid_fill' : 0.8, # FUTURE VERSION 

'ncpus' : ncpus, 

'pH' : '0,15', 

'pHstep' : 0.25, 

'logfile' : 'LOGFILE', 

'scaleM' : 4, 

'scaleP' : 1, 

'gsize' : 81, 

'convergence' : 0.01, 

'nlit' : 300, 

'cutoff' : -1, 

'relfac' : 0.0, 

'output' : 'pKas.out' 

} 

sites = {'A': ('1N', '2C')} 

pKa = Titration(parameters, sites=sites) 

 

checkAPIResult(pKa, results)