[Tutor] Labeling and Sorting a Test File

Stephen P. Molnar s.molnar at sbcglobal.net
Fri Jul 30 10:27:26 EDT 2021


First of all, let me say this is not a school exercise.

I have a project that I am working on that is going to generate a large 
number of text files, perhaps in the thousands.
The format of these files is:

Detected 8 CPUs
Reading input ... done.
Setting up the scoring function ... done.
Analyzing the binding site ... done.
Using random seed: -596016
Performing search ... done.

Refining results ... done.

mode |   affinity | dist from best mode
      | (kcal/mol) | rmsd l.b.| rmsd u.b.
-----+------------+----------+----------
    1    -4.780168282      0.000      0.000
    2    -4.767296818      8.730     11.993
    3    -4.709057289     13.401     15.939
    4    -4.677956834      8.271     11.344
    5    -4.633563903      8.581     11.967
    6    -4.569815226      4.730      8.233
    7    -4.540149947      8.578     11.959
    8    -4.515237403      8.096     10.215
    9    -4.514233086      5.064      7.689
Writing output ... done.

I have managed, through a combination of fruitlessly searching Google 
and making errors, this Python code (attached):

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

with open("Ligand.list") as ligands_f:
     for line in ligands_f:
         ligand = line.strip()
         for num in range(1,11):
             #print(ligand)
             name_in = "{}.{}.log".format(ligand,num)
             data = np.genfromtxt(name_in,skip_header=28, skip_footer=1)
             name_s = ligand+'-BE'
             f = open(name_s, 'a')
             f.write(str(data[1,1])+'\n')
             f.close()

The result of applying the code to ten files is:

-4.709057289
-4.66850894
-4.747875776
-4.631865671
-4.661709186
-4.686041874
-4.632855261
-4.617575733
-4.734570162
-4.727217506

This is almost the way I want the file, with two problems:

1. I want to the first line in the textile to be the name of the file, 
in the example 'Test'.

2. I want the list sorted in the order of decreasing negative order:

-4.747875776
-4.734570162
-4.727217506
-4.709057289
-4.686041874
-4.66850894
-4.661709186
-4.632855261
-4.631865671
-4.617575733

As my Python programming skills are limited, at best, I would appreciate 
some pointers in the right direction to implement the answers to my 
questions.

Thanks in advance.

-- 
Stephen P. Molnar, Ph.D.
614.312.7528 (c)
Skype:  smolnar1

-------------- next part --------------
-4.709057289
-4.66850894
-4.747875776
-4.631865671
-4.661709186
-4.686041874
-4.632855261
-4.617575733
-4.734570162
-4.727217506


More information about the Tutor mailing list