Automatic Folder Creation

The module pysoftk.folder_manager.folder_creator is a set of Python tools that provides a range of functionalities to carry out high-throughput calculations (HTPc).

In the first instance, the creation of a user-defined number of folders with unique labels can be achieved in the following lines of code:

from pysoftk.folder_manager.folder_creator import *

# Create 2 folders with unique labels using 1 core.
Fld().create(2)

The function receives as the first argument the number of folders to be created, whilst the second argument declares the number of cores used to perform this operation. We can verify the creation of these folders by typing the following command:

$ tree
.
├── 37c49461ba7b4206ba5cc5c101485faa
├── f819d762c1234f89a1bd762022a5007c
└── test_fol_m.py

where it can be seen that the two folders (with unique alphanumeric labels) have been succesfully created in a folder where the test_fol_m.py is located.

Similarly, PySoftK is able to seek for files with a user-provided extension (such as .smi, .pdb, .mol, .xyz, etc).

from rdkit import Chem
from rdkit.Chem import AllChem

print('c1cc(sc1Br)Br',file=open("mol_1.smi", 'w'))
print('c1(ccc(cc1)Br)Br', file=open("mol_2.smi",'w'))

# Seek files with a given extension like: .smi, .mol, .pbd, .xyz, etc
a=Fld().seek_files("smi")

The variable a stores the absolute paths where the files mol_1.smi and mol_2.smi are stored. Likewise, the length of this list indicates the number of files with that given extension present in the current working directory.

Complementing these previous functions, PySoftK enables the automatic moving of the files into unique labeled folders as indicated in the following snipet:

from rdkit import Chem
from rdkit.Chem import AllChem

print('c1cc(sc1Br)Br',file=open("mol_1.smi", 'w'))
print('c1(ccc(cc1)Br)Br', file=open("mol_2.smi",'w'))

# Test 3: Seek for .smi files and create the needed directories using 2 cores.
Fld().file_to_dir("smi",2)

To verify that the files have correctly moved, we can use the tree bash command as indicated above:

$ tree

├── 8fa730a5245c4656ac305a7ecc9bba07
│   └── mol_2.smi
├── b38be2d4de134b49915c7d8c694959f3
│   └── mol_1.smi
└── test_folder.py

2 directories, 3 files

As shown above, the files mol_1.smi and mol_2.smi have been correcty allocated into unique folders. This collection of PySoftK tools has been developed to be used independent of the Polymer module and intended to be used as stand-alone or in conjunction with the HTPc tools.