3232from Bio .PDB import calc_angle as pdb_calc_angle
3333from Bio .PDB import calc_dihedral as pdb_calc_dihedral
3434from django .db import transaction
35+ import django
3536
3637from pgd_core .models import (Protein as ProteinModel , Chain as ChainModel ,
3738 Residue as ResidueModel , Sidechain_ARG ,
4546from pgd_splicer .chi import CHI_MAP , CHI_CORRECTIONS_TESTS , CHI_CORRECTIONS
4647from pgd_splicer .sidechain import bond_angles , bond_lengths
4748
49+ django .setup ()
4850
4951def NO_VALUE (field ):
5052 """
@@ -195,12 +197,12 @@ def workhorse(data):
195197 return False
196198
197199
198- @ transaction . commit_manually
200+
199201def process_pdb (data ):
200202 """
201203 Process an individual pdb file
202204 """
203-
205+ transaction . set_autocommit ( False )
204206 # create a copy of the data. This dict will have a large amount of data
205207 # added to it as the protein is processed. This prevents memory leaks
206208 # due to the original dict having a reference held outside this method.
@@ -233,8 +235,10 @@ def process_pdb(data):
233235 protein .rfactor = float (data ['rfactor' ])
234236 protein .rfree = float (data ['rfree' ])
235237 protein .pdb_date = data ['pdb_date' ]
236- protein .save ()
238+ with transaction .atomic ():
239+ protein .save ()
237240
241+ transaction .commit ()
238242 # 3) Get/Create Chains and save values
239243 chains = {}
240244 for chaincode , residues in data ['chains' ].items ():
@@ -248,9 +252,10 @@ def process_pdb(data):
248252 chain .id = chainId
249253 chain .protein = protein
250254 chain .code = chaincode
251- chain .save ()
255+ with transaction .atomic ():
256+ chain .save ()
252257
253- protein .chains .add (chain )
258+ protein .chains .add (chain )
254259 #create dictionary of chains for quick access
255260 chains [chaincode ] = chain
256261
@@ -288,17 +293,20 @@ def process_pdb(data):
288293 except :
289294 sidechain = klass ()
290295 sidechain .__dict__ .update (residue_props ['sidechain' ])
291- sidechain .save ()
296+ with transaction .atomic ():
297+ sidechain .save ()
292298 residue .__setattr__ (name , sidechain )
293299
294300 # 4e) save
295- residue .save ()
296- chain .residues .add (residue )
301+ with transaction .atomic ():
302+ residue .save ()
303+ chain .residues .add (residue )
297304
298305 # 4f) Update old_residue.next
299306 if "prev" in residue_props :
300307 old_residue .next = residue
301- old_residue .save ()
308+ with transaction .atomic ():
309+ old_residue .save ()
302310
303311
304312 old_residue = residue
0 commit comments