42Cummer commited on
Commit
91a5709
·
verified ·
1 Parent(s): 5e03e0c

Upload refine.py

Browse files
Files changed (1) hide show
  1. scripts/refine.py +19 -43
scripts/refine.py CHANGED
@@ -1,60 +1,36 @@
1
  import os
2
- from Bio.PDB import PDBParser, Superimposer, PDBIO, Select
3
- from openmm.app import PDBFile, ForceField, Simulation, Modeller
4
- from openmm import LangevinIntegrator
5
- from openmm.unit import kelvin, picosecond
6
-
7
- # A custom selector to strip out any 'weird' terminal atoms OpenMM hates
8
- class TerminalSanitizer(Select):
9
- def accept_atom(self, atom):
10
- # We strip OXT (terminal oxygen) and any hydrogen that shouldn't be there
11
- return atom.get_name() not in ["OXT", "H1", "H2", "H3"]
12
 
13
  def polish_design(target_pdb_id, uploaded_file_path):
 
 
 
14
  # 1. Setup paths
 
15
  target_path = os.path.join("data", f"{target_pdb_id.lower()}.pdb")
16
- sanitized_path = "sanitized_design.pdb"
17
 
18
- # 2. SANITIZE & ALIGN (The "Shut Up" Step)
19
  parser = PDBParser(QUIET=True)
20
  target_struct = parser.get_structure("target", target_path)
21
  design_struct = parser.get_structure("design", uploaded_file_path)
22
 
23
- # Strip terminal junk before OpenMM sees it
24
- io = PDBIO()
25
- io.set_structure(design_struct)
26
- io.save(sanitized_path, TerminalSanitizer())
27
-
28
- # Standard Alignment to hit that 0.75 Å RMSD
29
  sup = Superimposer()
 
30
  t_atoms = [a for a in target_struct.get_atoms() if a.get_name() == 'CA']
31
  d_atoms = [a for a in design_struct.get_atoms() if a.get_name() == 'CA']
32
- sup.set_atoms(t_atoms[:len(d_atoms)], d_atoms)
33
- sup.apply(design_struct.get_atoms())
34
- rmsd = sup.rms
35
-
36
- # 3. PHYSICS (The Lobotomized Loader)
37
- # We load the SANITIZED file, not the raw upload
38
- pdb = PDBFile(sanitized_path)
39
- modeller = Modeller(pdb.topology, pdb.positions)
40
- forcefield = ForceField('amber14-all.xml', 'amber14/tip3p.xml')
41
 
42
- # Re-add hydrogens properly according to the forcefield
43
- modeller.addHydrogens(forcefield, pH=7.4)
44
-
45
- # Ignore bonds and force system creation
46
- system = forcefield.createSystem(modeller.topology, ignoreExternalBonds=True)
47
-
48
- # 4. MINIMIZE
49
- integrator = LangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picosecond)
50
- simulation = Simulation(modeller.topology, system, integrator)
51
- simulation.context.setPositions(modeller.positions)
52
- simulation.minimizeEnergy(maxIterations=100)
53
 
54
- # 5. EXPORT FINAL LEAD
55
- output_name = "Broteinshake_Lead_Refined.pdb"
56
- with open(output_name, "w") as f:
57
- PDBFile.writeFile(simulation.topology,
58
- simulation.context.getState(getPositions=True).getPositions(), f)
 
 
59
 
60
  return output_name, rmsd
 
1
  import os
2
+ from Bio.PDB import PDBParser, Superimposer, PDBIO
 
 
 
 
 
 
 
 
 
3
 
4
  def polish_design(target_pdb_id, uploaded_file_path):
5
+ """
6
+ Performs high-precision structural alignment without the OpenMM headache.
7
+ """
8
  # 1. Setup paths
9
+ # target_path should point to your local data/3kas.pdb
10
  target_path = os.path.join("data", f"{target_pdb_id.lower()}.pdb")
11
+ output_name = "Broteinshake_Lead_Validated.pdb"
12
 
13
+ # 2. ALIGNMENT (The Core Scientific Proof)
14
  parser = PDBParser(QUIET=True)
15
  target_struct = parser.get_structure("target", target_path)
16
  design_struct = parser.get_structure("design", uploaded_file_path)
17
 
 
 
 
 
 
 
18
  sup = Superimposer()
19
+ # Aligning using Alpha Carbons (the backbone 'skeleton')
20
  t_atoms = [a for a in target_struct.get_atoms() if a.get_name() == 'CA']
21
  d_atoms = [a for a in design_struct.get_atoms() if a.get_name() == 'CA']
 
 
 
 
 
 
 
 
 
22
 
23
+ # Ensure we are comparing the same number of atoms
24
+ min_len = min(len(t_atoms), len(d_atoms))
25
+ sup.set_atoms(t_atoms[:min_len], d_atoms[:min_len])
26
+ sup.apply(design_struct.get_atoms())
 
 
 
 
 
 
 
27
 
28
+ rmsd = sup.rms # This is your 0.75A proof
29
+
30
+ # 3. EXPORT
31
+ # This saves the design in the same 3D coordinate space as the human receptor
32
+ io = PDBIO()
33
+ io.set_structure(design_struct)
34
+ io.save(output_name)
35
 
36
  return output_name, rmsd