In [1]:
pwd
Out[1]:
In [2]:
cd ../molecules/
In [3]:
pwd
Out[3]:
In [4]:
ls
In [5]:
input_file = open('methane.pdb')
In [6]:
type(input_file)
Out[6]:
In [14]:
input_file = open('methane.pdb')
for line in input_file:
line = line.rstrip()
print line
In [15]:
input_file = open('mehane.pdb')
for line in input_file:
line = line.rstrip()
print line
In [22]:
def print_file(filename):
try:
input_file = open(filename)
except IOError as ex:
print 'I got an error when opening', filename, ':', ex.strerror
else:
for line in input_file:
line = line.rstrip()
print line
In [24]:
filename = 'methane.pdb'
print_file(filename)
In [28]:
def count_atom(filename, atom_type):
try:
input_file = open(filename)
except IOError as ex:
print 'I got an error when opening', filename, ':', ex.strerror
else:
atom_count = 0
for line in input_file:
line = line.rstrip()
if line.startswith('ATOM'):
fields = line.split()
if fields[2] == atom_type:
atom_count = atom_count + 1
return atom_count
In [30]:
count_atom('methane.pdb', 'C')
Out[30]:
In [ ]: