#!/usr/bin/env python ''' Changes "randomly" atom occupancies to a particular value. If e.g. divisor = 10 and part = 3, then it changes the occupancy of 3 successive atoms and let the original occupancy of 7 successive atoms. And round and round... If cyclus_start=0, the FIRST 3 atoms are modified, it is possible to shift the divisor-fold cycling by this parameter. Usage: python change_some_occupancies.py structure.pdb Then the output file is structure.pdb_occ.pdb. ''' __author__ = "Martin Maly" __license__ = "Creative Commons Attribution 4.0 International License" __email__ = "malymar9@fjfi.cvut.cz" import sys # # # Setting # # # divisor = 10 part = 3 set_occupancy_to = "0.10" cyclus_start = 0 # # # Script # # # filename_in = sys.argv[1] filename_out = sys.argv[1] + "_occ.pdb" with open(filename_in, "r") as file: lines = file.readlines() counter = cyclus_start - 1 for i in range(len(lines)): if lines[i][0:6] == "ATOM " or lines[i][0:6] == "HETATM": counter += 1 for j in range(part): if counter % divisor == j: lines[i] = lines[i][:56] + set_occupancy_to + lines[i][60:] with open(filename_out, "w") as file: file.writelines(lines)