[Tutor] Why Doesn't the for loop Increment?

Stephen P. Molnar s.molnar at sbcglobal.net
Tue Jan 12 14:32:36 EST 2021


Python3.7.3 on Debian Buster.

I have a large number of computational docking files from which I wish 
to extract results.

I have cobbled together a script that works, up to a point:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np

df = pd.read_csv('ligands_3')
num = [1,2,3,4,5,6,7,8,9,10]

for ligand in df:
     for i in num:
         name_in = "{}.{}.log".format(ligand, i)
         data = np.genfromtxt(name_in,skip_header=28, skip_footer=1)
         name_s = ligand+'-BE'
         f = open(name_s, 'a')
         f.write(str(data[0,1])+'\n')
         f.close()

For each ligand I run ten repetitions of the docking. The ligands_3 file 
contains three ligand names:

7-Phloroeckol
Aloeemodin
beta-Sitosterol

The code produces, for example, for the first ligand in the list:

-9.248153586
-9.174749259
-8.941017151
-9.162562472
-9.17411506
-9.217528128
-9.133030378
-9.182355251
-9.298771543
-9.300577161

Which happen to be correct.

The problem, though, is that the script does not go on to the next 
ligand in the list. Everything that I have found in Google results says 
that the script will iterate through the list.

What have I done or not done?

I will be most appreciate of suggestions. Thanks in advance.

-- 
Stephen P. Molnar, Ph.D.
www.molecular-modeling.net
614.312.7528 (c)
Skype:  smolnar1



More information about the Tutor mailing list