Created
December 5, 2014 11:10
-
-
Save kohnakagawa/5a4736ec9bdbdcda0435 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import sys, math, re | |
| argvs = sys.argv | |
| if (len(argvs) != 4): | |
| print "Usage $ python %s input_filename output_filename offset_length" % argvs[0] | |
| quit() | |
| print "Generate ribon bilayer. Stripe length is 2*Lx" | |
| def ReadLineGro(line): | |
| ret = [] | |
| ret.append(int(line[0:5])) | |
| ret.append(line[5 :10].strip()) | |
| ret.append(line[10:15].strip()) | |
| ret.append(int(line[15:20])) | |
| ret.append(float(line[20:28])) | |
| ret.append(float(line[28:36])) | |
| ret.append(float(line[36:44])) | |
| return ret | |
| def RetLipidName(line): | |
| ret = str(line[0]) + line[1] | |
| return ret | |
| rf = open(argvs[1], "r") | |
| rem_d = float(argvs[3]) | |
| rf_lines = rf.readlines() | |
| comment = rf_lines[0] | |
| alln = int(rf_lines[1].split()[0]) | |
| boxleng = [float(i) for i in rf_lines[-1].split()] | |
| Lipids = [] | |
| Waters = [] | |
| cur_lipid = RetLipidName(ReadLineGro(rf_lines[2])) | |
| flag = ReadLineGro(rf_lines[2])[5] < rem_d | |
| for line in rf_lines[2:len(rf_lines)-1]: | |
| line_dat = ReadLineGro(line) | |
| lip_name = RetLipidName(line_dat) | |
| if(line_dat[2] != 'W'): | |
| if(lip_name != cur_lipid): | |
| flag = line_dat[5] < rem_d | |
| cur_lipid = lip_name | |
| if(flag): | |
| Waters.append(line_dat) | |
| else: | |
| Lipids.append(line_dat) | |
| else: | |
| Waters.append(line_dat) | |
| wf = open(argvs[2], "w") | |
| wf.write(comment) | |
| wf.write(str(alln)+'\n') | |
| cur_lipid = RetLipidName(Lipids[0]) | |
| mol_id = 1 | |
| atom_id = 1 | |
| for lipid in Lipids: | |
| lip_name = RetLipidName(lipid) | |
| if(lip_name != cur_lipid): | |
| cur_lipid = lip_name | |
| mol_id += 1 | |
| wf.write("%5d%-5s%5s%5d%8.3f%8.3f%8.3f\n"%(mol_id, lipid[1], lipid[2], atom_id, lipid[4], lipid[5], lipid[6])) | |
| atom_id += 1 | |
| mol_id += 1 | |
| for water in Waters: | |
| wf.write("%5d%-5s%5s%5d%8.3f%8.3f%8.3f\n"%(mol_id, 'W', 'W', atom_id, water[4], water[5], water[6])) | |
| atom_id += 1 | |
| mol_id += 1 | |
| wf.write("%10.5f%10.5f%10.5f\n"%(boxleng[0], boxleng[1], boxleng[2])) | |
| rf.close() | |
| wf.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generate ribon membrane.