# Author: Carsten Sachse 24-Apr-2016
"""
This python script creates a list of stack_ids based on removing the ends of each helical particle.
"""
#=======================================================================================================================
# input parameters to be edited:
#=======================================================================================================================
stepsize_in_A = 70
segment_size_A = 700
spring_db = 'spring.db'
segment_outfile = 'excluded_ends_stack_ids.dat'
#=======================================================================================================================
# actual script; no editing needed beyond this point
#=======================================================================================================================
from spring.csinfrastr.csdatabase import SpringDataBase, base, HelixTable, SegmentTable
class SpringHelixEnds(object):
def remove_helix_ends(self, spring_db):
session = SpringDataBase().setup_sqlite_db(base, spring_db)
helices = session.query(HelixTable).order_by(HelixTable.id).all()
helix_ids = [each_helix.id for each_helix in helices]
f = open(segment_outfile, 'w')
remove_end_count = int(round(0.5 * segment_size_A / stepsize_in_A))
for each_helix_id in helix_ids:
segments = session.query(SegmentTable).filter(SegmentTable.helix_id == each_helix_id).all()
hel_stack_ids = [each_segment.stack_id for each_segment in segments]
hel_stack_ids_included = hel_stack_ids[remove_end_count:-remove_end_count]
hel_stack_ids_excluded = list(set(hel_stack_ids) - set(hel_stack_ids_included))
f.write('{0}\n'.format('\n'.join([str(each_helix_id) for each_helix_id in hel_stack_ids_excluded])))
f.close()
def main():
se = SpringHelixEnds()
se.remove_helix_ends(spring_db)
if __name__ == '__main__':
main()