-
Notifications
You must be signed in to change notification settings - Fork 2
🌐run with Google Colab
This tutorial explains how to use SFPPy in a Google Colab environment without a formal installation. It covers:
- Cloning the
SFPPyrepository (first time) or updating it (subsequent times). - Listing the directory contents.
- Running an example script.
- Adding the
SFPPyfolder to Python'ssys.pathto allow direct imports. - Run you own code
Before running SFPPy, you need to ensure the repository is present and up-to-date. The following code checks whether the SFPPy folder exists in your current working directory. If it does not exist, it performs a git clone. If it does, it updates the repository using git pull.
import os
if not os.path.exists("SFPPy"):
# First time: clone the repository
!git clone https://github.com/ovitrac/SFPPy.git
else:
# Subsequent times: update the repository (if needed)
!git -C SFPPy pullAfter cloning or updating, verify that the SFPPy folder is present by listing the current directory contents:
%lsTest the installation by running an example script provided by SFPPy. Assuming example1.py is in the current working directory (or adjust the path as needed):
!python example1.pyTo ensure you can import modules from SFPPy without a traditional installation, add the folder to Python's sys.path if it is not already included. The code below retrieves the current working directory and appends it to sys.path if necessary:
import sys
import os
SFPPyfolder = os.getcwd() # Get the current working directory
print(f"Current path: {SFPPyfolder}")
if SFPPyfolder not in sys.path:
sys.path.append(SFPPyfolder)
print(f"Added {SFPPyfolder} to sys.path")
else:
print(f"{SFPPyfolder} already in sys.path")Once you have set up SFPPy, you can simply write or paste any SFPPy-related code into a cell and run it. Below is an example that checks if you can import substances from SFPPy.
In this example, we import the migrant function from patankar.loadpubchem and use it to process a list of substances. You can continue your script as usual after this test.
# %% Place your code below
from patankar.loadpubchem import migrant
list_of_migrants = ["toluene", "limonene", "BHT", "Irganox 1076"]
m = [migrant(s) for s in list_of_migrants]
print(m)
⚠️ Note: All imports of SFPPy modules must include thepatankarprefix.
By following these steps, you can work with SFPPy in Google Colab without performing a traditional installation. Clone the repository the first time, update it in subsequent sessions, list the contents to confirm its presence, run an example to verify functionality, and finally, ensure the folder is in your Python path for seamless imports