By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

How to count total number of water ('HOH') molecules in each file ?

P: 6
import os
print path
print list_of_filenames
for f in list_of_filenames:
for line in f1:
if line.startswith('HETATM'):
if res_number not in residue and line[17:20]=='HOH':

As the output of this script I got only one value which is the total number of 'HOH' molecules in all the files in that directory. But I need to count total number of 'HOH' molecules in each file one by one.
So please can you help me to find out how this script should be changed according to my requirement?
Mar 12 '17 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 621
Expand|Select|Wrap|Line Numbers
  1. for f in list_of_filenames:
  2.     residue=[]  ## new list for each name
  3.     f1=open(patf1=open(path+'//newfiles//'+f).readlines()
  4.     for line in f1:
  5.         ...
  6.     print(len(residue))  ## for each name 
And note that else + continue does nothing. Try it for yourself and see what happens.
Mar 12 '17 #2

P: 6
@dwblas Thank you. I will try.
Mar 13 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.