-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
142 lines (122 loc) · 4.53 KB
/
script.js
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
const fileInput = document.getElementById('fileInput');
const lengthElement = document.getElementById('length');
const atomWeightElement = document.getElementById('atomWeight');
const hetatmWeightElement = document.getElementById('hetatmWeight');
const hbAcceptorsElement = document.getElementById('hbAcceptors');
const hbDonorsElement = document.getElementById('hbDonors');
const phRangeInput = document.getElementById('phRange');
const calculateButton = document.getElementById('calculateButton');
const logPElement = document.getElementById('logP');
const atomicWeights = {
'H': 1.0079,
'C': 12.0107,
'N': 14.0067,
'O': 15.9994
// ... Add more elements and their weights
};
const hbAcceptorAtoms = new Set(['O', 'N']); // Hydrogen bond acceptor atoms
const hbDonorAtoms = new Set(['H', 'N']); // Hydrogen bond donor atoms
function extractEntriesFromPDB(pdbContent, entryType) {
const lines = pdbContent.split('\n');
const entries = [];
for (const line of lines) {
if (line.startsWith(entryType)) {
entries.push(line);
}
}
return entries;
}
function calculateMolecularWeight(entries) {
let molecularWeight = 0;
for (const entry of entries) {
const atomElement = entry.slice(12, 14).trim();
if (atomicWeights[atomElement]) {
molecularWeight += atomicWeights[atomElement];
}
}
return molecularWeight;
}
function countHydrogenBondAcceptors(entries, ph) {
let count = 0;
for (const entry of entries) {
const atomElement = entry.slice(12, 14).trim();
if (hbAcceptorAtoms.has(atomElement) && isAcceptorAtGivenpH(atomElement, ph)) {
count++;
}
}
return count;
}
function countHydrogenBondDonors(entries, ph) {
let count = 0;
for (const entry of entries) {
const atomElement = entry.slice(12, 14).trim();
if (hbDonorAtoms.has(atomElement) && isDonorAtGivenpH(atomElement, ph)) {
count++;
}
}
return count;
}
function isAcceptorAtGivenpH(atom, ph) {
// Define ionization states of atoms based on pH (pKa values)
const ionizationStates = {
'O': ph > 2, // Ionized above pH 2 (carboxylate)
'N': ph > 9 // Ionized above pH 9 (ammonium)
};
return ionizationStates[atom];
}
function isDonorAtGivenpH(atom, ph) {
// Define ionization states of atoms based on pH (pKa values)
const ionizationStates = {
'H': ph < 7, // Ionized below pH 7 (protonated)
'N': ph < 7 // Ionized below pH 7 (protonated)
};
return ionizationStates[atom];
}
function calculateLogP(hbAcceptors, hbDonors) {
// A simplified formula for calculating Log P
// Note: This is a very simplified example, actual Log P calculations are more complex
return hbDonors - hbAcceptors;
}
calculateButton.addEventListener('click', function() {
const phValue = parseFloat(phRangeInput.value);
if (!isNaN(phValue)) {
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const pdbContent = e.target.result;
const atomEntries = extractEntriesFromPDB(pdbContent, 'ATOM');
const hetatmEntries = extractEntriesFromPDB(pdbContent, 'HETATM');
const atomWeight = calculateMolecularWeight(atomEntries);
const hetatmWeight = calculateMolecularWeight(hetatmEntries);
const hbAcceptors = countHydrogenBondAcceptors(atomEntries.concat(hetatmEntries), phValue);
const hbDonors = countHydrogenBondDonors(atomEntries.concat(hetatmEntries), phValue);
const totalMass = atomWeight + hetatmWeight;
atomWeightElement.textContent = atomWeight.toFixed(4) + ' g/mol';
hetatmWeightElement.textContent = hetatmWeight.toFixed(4) + ' g/mol';
hbAcceptorsElement.textContent = hbAcceptors;
hbDonorsElement.textContent = hbDonors;
// Calculate Log P
const logP = calculateLogP(hbAcceptors, hbDonors);
logPElement.textContent = logP.toFixed(2);
// Calculate Lipinski's Rule of Five violations
let numViolations = 0;
if (totalMass > 500) {
numViolations++;
}
if (hbAcceptors > 10) {
numViolations++;
}
if (logP > 5) {
numViolations++;
}
if (atomEntries.length + hetatmEntries.length > 50) {
numViolations++;
}
const violationsElement = document.getElementById('violations');
violationsElement.textContent = numViolations;
};
reader.readAsText(file);
}
}
});