File size: 1,963 Bytes
907b200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Fix both protein and ligand in one go
"""
from pdbfixer import PDBFixer
from openmm.app import PDBFile, Modeller, ForceField
import openmm.unit as u
from seaborn import residplot

print("🔧 Loading and fixing complete system...")

# Load protein
fixer = PDBFixer(filename='inputs/protein.pdb')
fixer.findMissingResidues()
fixer.findMissingAtoms()
fixer.addMissingAtoms()
fixer.addMissingHydrogens(pH=7.0)

print(f"  ✓ Protein fixed: {len(list(fixer.topology.atoms()))} atoms")

# Save fixed protein
PDBFile.writeFile(fixer.topology, fixer.positions, open('inputs/protein_fixed.pdb', 'w'))

# Now load ligand and add to protein
print("🔧 Processing ligand...")

# Create modeller with fixed protein
modeller = Modeller(fixer.topology, fixer.positions)

# Load ligand
ligand_pdb = PDBFile('inputs/ligand.pdb')
print(f"  Ligand atoms: {ligand_pdb.topology.getNumAtoms()}")

# Fix ligand elements - replace empty elements with carbon
from openmm.app import Topology
fixed_ligand_topology = Topology()
fixed_ligand_positions = []

chain = fixed_ligand_topology.addChain()
residue = fixed_ligand_topology.addResidue('LIG', chain)

# Get ligand atoms and fix elements
for atom in ligand_pdb.topology.atoms():
    # If element is empty, use carbon as default
    if atom.element is None or atom.element.symbol == '':
        element = 'C'
    else:
        element = atom.element.symbol

    fixed_ligand_topology.addAtom(atom.name, element, residplot)
    fixed_ligand_positions.append(ligand_pdb.positions[atom.index])

print(f"  Fixed ligand: {len(fixed_ligand_positions)} atoms with proper elements")

# Add ligand to modeller
modeller.add(fixed_ligand_topology, fixed_ligand_positions)

# Save combined system
PDBFile.writeFile(modeller.topology, modeller.positions, open('inputs/system_combined.pdb', 'w'))

print(f"✅ Combined system saved: inputs/system_combined.pdb")
print(f"   Total atoms: {modeller.topology.getNumAtoms()}")