@@ -12,13 +12,25 @@ def convert_pdb(pdb_file, output_xyz_file):
1212 for res in traj .topology .residues :
1313 if not res .is_protein :
1414 continue
15+
1516 cm = [0.0 , 0.0 , 0.0 ] # residue mass center
1617 mw = 0.0 # residue weight
1718 for a in res .atoms :
19+ # Add N-terminal
20+ if res .index == 0 and a .index == 0 and a .name == "N" :
21+ print ("Adding N-terminal bead" )
22+ residues .append (dict (name = "NTR" , cm = traj .xyz [0 ][a .index ] * 10 ))
23+
24+ # Add C-terminal
25+ if a .name == "OXT" :
26+ print ("Adding C-terminal bead" )
27+ residues .append (dict (name = "CTR" , cm = traj .xyz [0 ][a .index ] * 10 ))
28+
29+ # Add coarse grained bead
1830 cm = cm + a .element .mass * traj .xyz [0 ][a .index ]
1931 mw = mw + a .element .mass
20- cm = cm / mw * 10.0
21- residues .append (dict (name = res .name , cm = cm ))
32+
33+ residues .append (dict (name = res .name , cm = cm / mw * 10 ))
2234
2335 if "sidechains" in sys .argv :
2436 side_chain = add_sidechains (traj , res )
@@ -27,7 +39,7 @@ def convert_pdb(pdb_file, output_xyz_file):
2739
2840 with open (output_xyz_file , "w" ) as f :
2941 f .write (f"{ len (residues )} \n " )
30- f .write (f"Converted with Duello pdb2xyz.py using input file { pdb_file } \n " );
42+ f .write (f"Converted with Duello pdb2xyz.py using input file { pdb_file } \n " )
3143 for i in residues :
3244 f .write (f"{ i ['name' ]} { i ['cm' ][0 ]:.3f} { i ['cm' ][1 ]:.3f} { i ['cm' ][2 ]:.3f} \n " )
3345 print (f"Converted { pdb_file } -> { output_xyz_file } with { len (residues )} residues." )
0 commit comments