javascript
// Peptide Dissolve Calculator
const app = document.getElementById('app');
// Create UI elements
app.innerHTML = `
<div class="calculator-container">
<h1>Peptide Dissolve Calculator</h1>
<div class="input-group">
<label for="peptide-weight">Peptide Weight (mg):</label>
<input type="number" id="peptide-weight" placeholder="Enter weight" min="0" step="0.001">
</div>
<div class="input-group">
<label for="molecular-weight">Molecular Weight (g/mol):</label>
<input type="number" id="molecular-weight" placeholder="Enter MW" min="0" step="0.01">
</div>
<div class="input-group">
<label for="desired-concentration">Desired Concentration:</label>
<div class="concentration-inputs">
<input type="number" id="concentration-value" placeholder="Value" min="0" step="0.01">
<select id="concentration-unit">
<option value="mM">mM</option>
<option value="μM">μM</option>
<option value="nM">nM</option>
<option value="mg/mL">mg/mL</option>
<option value="μg/mL">μg/mL</option>
</select>
</div>
</div>
<button id="calculate-btn">Calculate</button>
<div class="results" id="results">
<div class="result-card">
<h3>Required Solvent Volume</h3>
<p id="volume-result">-</p>
</div>
<div class="result-card">
<h3>Molar Amount</h3>
<p id="molar-result">-</p>
</div>
</div>
<div class="solvent-tips">
<h3>Solvent Recommendations</h3>
<div id="solvent-recommendations">
Select peptide properties for recommendations
</div>
</div>
</div>
<style>
.calculator-container {
max-width: 500px;
margin: 0 auto;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
background: #fff;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
h1 {
color: #2c3e50;
font-size: 24px;
margin-bottom: 24px;
text-align: center;
}
.input-group {
margin-bottom: 16px;
}
label {
display: block;
margin-bottom: 6px;
font-weight: 500;
color: #34495e;
}
input, select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 16px;
}
.concentration-inputs {
display: flex;
gap: 8px;
}
#concentration-value {
flex: 2;
}
#concentration-unit {
flex: 1;
}
button {
width: 100%;
padding: 12px;
background: #3498db;
color: white;
border: none;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background 0.3s;
margin: 16px 0;
}
button:hover {
background: #2980b9;
}
.results {
display: flex;
gap: 16px;
margin-top: 20px;
}
.result-card {
flex: 1;
background: #f8f9fa;
padding: 16px;
border-radius: 8px;
text-align: center;
}
.result-card h3 {
font-size: 16px;
margin-top: 0;
color: #2c3e50;
}
.result-card p {
font-size: 18px;
font-weight: 600;
color: #3498db;
margin: 8px 0 0;
}
.solvent-tips {
margin-top: 24px;
padding: 16px;
background: #f1f8fe;
border-radius: 8px;
}
.solvent-tips h3 {
margin-top: 0;
font-size: 16px;
color: #2c3e50;
}
</style>
`;
// Add calculator logic
document.getElementById('calculate-btn').addEventListener('click', () => {
const peptideWeight = parseFloat(document.getElementById('peptide-weight').value);
const molecularWeight = parseFloat(document.getElementById('molecular-weight').value);
const concentrationValue = parseFloat(document.getElementById('concentration-value').value);
const concentrationUnit = document.getElementById('concentration-unit').value;
if (!peptideWeight || !molecularWeight || !concentrationValue) {
alert('Please fill in all fields');
return;
}
// Calculate moles
const moles = peptideWeight / 1000 / molecularWeight;
// Calculate volume based on concentration unit
let volumeInML;
switch(concentrationUnit) {
case 'mM':
volumeInML = moles * 1000;
break;
case 'μM':
volumeInML = moles * 1000000;
break;
case 'nM':
volumeInML = moles * 1000000000;
break;
case 'mg/mL':
volumeInML = peptideWeight;
break;
case 'μg/mL':
volumeInML = peptideWeight * 1000;
break;
}
// Display results
document.getElementById('volume-result').textContent =
`${(volumeInML / concentrationValue).toFixed(3)} mL`;
document.getElementById('molar-result').textContent =
`${(moles * 1000000).toFixed(3)} μmol`;
// Provide solvent recommendations
provideSolventRecommendations(molecularWeight);
});
function provideSolventRecommendations(molecularWeight) {
let recommendations = '';
if (molecularWeight < 1000) {
recommendations = `
<p><strong>Small peptides (MW < 1000):</strong></p>
<p>• Water is usually sufficient for hydrophilic peptides</p>
<p>• For hydrophobic peptides, try DMSO or dilute acetic acid (10%)</p>
`;
} else if (molecularWeight < 3000) {
recommendations = `
<p><strong>Medium peptides (MW 1000-3000):</strong></p>
<p>• Try water first for hydrophilic peptides</p>
<p>• For moderate hydrophobicity, use 10-20% acetonitrile in water</p>
<p>• For hydrophobic peptides, use DMSO or dilute (0.1%) TFA</p>
`;
} else {
recommendations = `
<p><strong>Large peptides (MW > 3000):</strong></p>
<p>• For hydrophilic peptides, PBS or physiological buffer</p>
<p>• For hydrophobic peptides, try 50% acetonitrile with 0.1% TFA</p>
<p>• Consider adding 5-10% DMSO to improve solubility</p>
`;
}
document.getElementById('solvent-recommendations').innerHTML = recommendations;
}