Open finlayiainmaclean opened 2 months ago
Hey @finlayiainmaclean,
This is an interesting error, which I just experienced for myself when running this on a RTX 4090 GPU - it does require a bit of tweaking of 2 files.
First for the setup.py script - if you replace your script with the following you should remove the g++
errors.
import os
import setuptools
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
# Check for necessary environment variables
env_vars = ["RDBASE", "RDKIT_INCLUDE_DIR", "RDKIT_LIB_DIR", "RDKIT_DATA_DIR"]
for var in env_vars:
if var not in os.environ:
raise Exception(f"{var} environment variable not set.")
RDBASE = os.environ.get("RDBASE")
RDKIT_INCLUDE_DIR = os.environ.get("RDKIT_INCLUDE_DIR")
RDKIT_LIB_DIR = os.environ.get("RDKIT_LIB_DIR")
# Find necessary RDKit components
MyRDKit_FIND_COMPONENTS = ["GraphMol", "SmilesParse", "FileParsers", "Depictor"]
RDKIT_LIBRARIES = []
for component in MyRDKit_FIND_COMPONENTS:
library_path = os.path.join(RDKIT_LIB_DIR, f"libRDKit{component}.so")
if not os.path.isfile(library_path):
raise Exception(f"Didn't find RDKit {component} library.")
RDKIT_LIBRARIES.append(library_path)
PAPER_DIR = "paper"
CCFLAGS = [
"-O2",
f"-I{RDKIT_INCLUDE_DIR}",
"-DORIG_GLOBAL",
"-DFAST_OVERLAP",
"-DNO_DIV_ADDRESS",
]
PTXFLAGS = ["-Xcompiler", "-O2", "-arch", "sm_50", "-Xptxas", "-v"]
LDFLAGS = [f"-L{RDKIT_LIB_DIR}"]
# Locate CUDA configuration
def locate_cuda():
home = os.environ.get("CUDA_HOME")
if not home:
raise Exception("CUDA_HOME environment variable not set.")
nvcc = os.path.join(home, "bin", "nvcc")
cudaconfig = {
"home": home,
"nvcc": nvcc,
"include": os.path.join(home, "include"),
"lib64": os.path.join(home, "lib64"),
}
for k, v in cudaconfig.items():
if not os.path.exists(v):
raise EnvironmentError(f"The CUDA {k} path could not be located in {v}")
return cudaconfig
# Customize the compiler for nvcc
def customize_compiler_for_nvcc(self):
self.src_extensions.append(".cu")
default_compiler_so = self.compiler_so
super_compile = self._compile
def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
if os.path.splitext(src)[1] == ".cu":
self.set_executable("compiler_so", CUDA["nvcc"])
postargs = extra_postargs["nvcc"]
else:
self.set_executable("compiler_so", default_compiler_so)
postargs = extra_postargs["gcc"]
super_compile(obj, src, ext, cc_args, postargs, pp_opts)
self.compiler_so = default_compiler_so # Reset after each compile
self._compile = _compile
# Custom build extension to handle CUDA compilation
class CustomBuildExt(build_ext):
def build_extensions(self):
customize_compiler_for_nvcc(self.compiler)
build_ext.build_extensions(self)
CUDA = locate_cuda()
# Define the extension
ext = Extension(
name="roshambo.cpaper",
sources=[
os.path.join("roshambo", "cpaper.pyx"),
os.path.join(PAPER_DIR, "deviceAnalyticVolume.cu"),
os.path.join(PAPER_DIR, "hostAnalyticVolume.cu"),
os.path.join(PAPER_DIR, "deviceOverlay.cu"),
os.path.join(PAPER_DIR, "transformTools.cu"),
os.path.join(PAPER_DIR, "inputFileReader.cpp"),
os.path.join(PAPER_DIR, "inputPreprocessor.cpp"),
os.path.join(PAPER_DIR, "inputModule.cu"),
],
include_dirs=[CUDA["include"], PAPER_DIR, RDKIT_INCLUDE_DIR],
library_dirs=[CUDA["lib64"], PAPER_DIR, RDKIT_LIB_DIR],
libraries=["cudart"],
language="c++",
runtime_library_dirs=[CUDA["lib64"], PAPER_DIR],
extra_compile_args={
"gcc": CCFLAGS + ["-std=c++17"], # C++ flags for g++
"nvcc": CCFLAGS + ["-std=c++17"] + PTXFLAGS + ["--ptxas-options=-v", "-c", "--compiler-options", "-fPIC"], # CUDA flags for nvcc
},
extra_link_args=LDFLAGS,
extra_objects=RDKIT_LIBRARIES,
)
# Load requirements.txt
with open("requirements.txt") as f:
requirements = f.read().splitlines()
# Setup configuration
setuptools.setup(
name="roshambo",
version="0.0.1",
author="Rasha Atwi",
author_email="rasha.atwi@biogen.edu",
description="roshambo is a python package for robust Gaussian molecular shape comparison",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/rashatwi/roshambo",
install_requires=requirements,
build_backend="setuptools.build_meta",
packages=setuptools.find_packages(),
entry_points={
"console_scripts": [
"roshambo = roshambo.cli:main",
],
},
classifiers=[
"Programming Language :: Python :: 3",
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Intended Audience :: Information Technology",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering :: Chemistry",
"Topic :: Software Development :: Libraries :: Python Modules",
],
python_requires=">=3.7",
include_package_data=True,
package_data={"roshambo": ["roshambo/*.cpython*.so"]},
ext_modules=[ext],
cmdclass={"build_ext": CustomBuildExt},
)
Annoyingly, you will still run into other issues, but these can be fixed by adding one line - #include <cuda_runtime.h>
to the cudaVolumeTypes.h
script in the paper
folder - the script I used is shown below:
/*
* cudaVolumeTypes.h
* Data structure definitions for PAPER
*
* Author: Imran Haque, 2009
* Copyright 2009, Stanford University
*
* This file is licensed under the terms of the GPL. Please see
* the COPYING file in the accompanying source distribution for
* full license terms.
*
*/
#ifndef _CUDAVOLUMETYPES_CU_
#define _CUDAVOLUMETYPES_CU_
typedef unsigned int uint;
#include <stdbool.h>
#include <cuda_runtime.h>
// Use this section if we're compiling under g++ instead of nvcc
#ifdef GPP
#include <unistd.h>
typedef struct _float4 {
float x,y,z,w;
} float4;
typedef struct _float3 {
float x,y,z;
} float3;
#endif
typedef struct _hCUDAmol {
float4* atoms;
uint natoms;
} CUDAmol;
typedef struct _dCUDAmol {
float* x;
float* y;
float* z;
float* a;
uint natoms;
} dCUDAmol;
typedef struct _dCUDAMultimol {
float* mols;
uint* atomcounts;
uint* molids;
uint maxatoms;
size_t pitch;
uint nmols;
float* transforms;
size_t transform_pitch;
bool isDeviceMM;
} dCUDAMultimol;
#endif
After updating both of the scripts you should be able to compile :)
pip install -e .
Obtaining file:///home/michael/DD_tools/roshambo
Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy==1.21.6 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from roshambo==0.0.1) (1.21.6)
Requirement already satisfied: pandas==1.3.5 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from roshambo==0.0.1) (1.3.5)
Requirement already satisfied: cython==0.29.33 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from roshambo==0.0.1) (0.29.33)
Requirement already satisfied: matplotlib==3.5.3 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from roshambo==0.0.1) (3.5.3)
Requirement already satisfied: scikit-learn==1.0.2 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from roshambo==0.0.1) (1.0.2)
Requirement already satisfied: scipy==1.7.3 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from roshambo==0.0.1) (1.7.3)
Requirement already satisfied: Pillow==9.4.0 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from roshambo==0.0.1) (9.4.0)
Requirement already satisfied: cairosvg==2.7.0 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from roshambo==0.0.1) (2.7.0)
Requirement already satisfied: cairocffi in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from cairosvg==2.7.0->roshambo==0.0.1) (1.7.1)
Requirement already satisfied: cssselect2 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from cairosvg==2.7.0->roshambo==0.0.1) (0.7.0)
Requirement already satisfied: defusedxml in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from cairosvg==2.7.0->roshambo==0.0.1) (0.7.1)
Requirement already satisfied: tinycss2 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from cairosvg==2.7.0->roshambo==0.0.1) (1.3.0)
Requirement already satisfied: cycler>=0.10 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from matplotlib==3.5.3->roshambo==0.0.1) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from matplotlib==3.5.3->roshambo==0.0.1) (4.54.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from matplotlib==3.5.3->roshambo==0.0.1) (1.4.7)
Requirement already satisfied: packaging>=20.0 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from matplotlib==3.5.3->roshambo==0.0.1) (24.1)
Requirement already satisfied: pyparsing>=2.2.1 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from matplotlib==3.5.3->roshambo==0.0.1) (3.1.4)
Requirement already satisfied: python-dateutil>=2.7 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from matplotlib==3.5.3->roshambo==0.0.1) (2.9.0)
Requirement already satisfied: pytz>=2017.3 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from pandas==1.3.5->roshambo==0.0.1) (2024.1)
Requirement already satisfied: joblib>=0.11 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from scikit-learn==1.0.2->roshambo==0.0.1) (1.4.2)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from scikit-learn==1.0.2->roshambo==0.0.1) (3.5.0)
Requirement already satisfied: six>=1.5 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from python-dateutil>=2.7->matplotlib==3.5.3->roshambo==0.0.1) (1.16.0)
Requirement already satisfied: cffi>=1.1.0 in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from cairocffi->cairosvg==2.7.0->roshambo==0.0.1) (1.17.1)
Requirement already satisfied: webencodings in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from cssselect2->cairosvg==2.7.0->roshambo==0.0.1) (0.5.1)
Requirement already satisfied: pycparser in /home/michael/miniconda3/envs/roshambo/lib/python3.9/site-packages (from cffi>=1.1.0->cairocffi->cairosvg==2.7.0->roshambo==0.0.1) (2.22)
Installing collected packages: roshambo
DEPRECATION: Legacy editable install of roshambo==0.0.1 from file:///home/michael/DD_tools/roshambo (setup.py develop) is deprecated. pip 25.0 will enforce this behaviour change. A possible replacement is to add a pyproject.toml or enable --use-pep517, and use setuptools >= 64. If the resulting installation is not behaving as expected, try using --config-settings editable_mode=compat. Please consult the setuptools documentation for more information. Discussion can be found at https://github.com/pypa/pip/issues/11457
Running setup.py develop for roshambo
Successfully installed roshambo
And just for sanity checking:
roshambo -h
usage: roshambo [-h] [--ignore_hs] [--n_confs N_CONFS] [--keep_mol] [--working_dir WORKING_DIR] [--name_prefix NAME_PREFIX] [--smiles_delimiter SMILES_DELIMITER]
[--gpu_id GPU_ID] [--volume_type {analytic,gaussian}] [--n N] [--proxy_cutoff PROXY_CUTOFF] [--epsilon EPSILON] [--res RES] [--margin MARGIN]
[--no_carbon_radii] [--color] [--fdef_path FDEF_PATH] [--sort_by SORT_BY] [--write_to_file] [--max_conformers MAX_CONFORMERS] [--filename FILENAME]
[--random_seed RANDOM_SEED] [--method {ETDG,ETKDG,ETKDGv2,ETKDGv3}] [--ff {UFF,MMFF94s,MMFF94s_noEstat}] [--opt_confs] [--calc_energy]
[--energy_iters ENERGY_ITERS] [--energy_cutoff ENERGY_CUTOFF] [--align_confs] [--rms_cutoff RMS_CUTOFF] [--num_threads NUM_THREADS]
ref_file dataset_files_pattern
Get similarity scores between a reference molecule and a dataset of molecules.
positional arguments:
ref_file Name of the reference molecule file.
dataset_files_pattern
File pattern to match the dataset molecule files.
optional arguments:
-h, --help show this help message and exit
--ignore_hs Ignore hydrogens.
--n_confs N_CONFS Number of conformers to generate.
--keep_mol Keep the original molecule in addition to the conformers.
--working_dir WORKING_DIR
Working directory.
--name_prefix NAME_PREFIX
Prefix to use for the molecule names if not found in the input files.
--smiles_delimiter SMILES_DELIMITER
Specify the delimiter for parsing SMILES. Use 'SPACE' for space, 'TAB' for tab, etc.
--gpu_id GPU_ID ID of the GPU to use for running PAPER.
--volume_type {analytic,gaussian}
The type of overlap volume calculation to use.
--n N The order of the analytic overlap volume calculation.
--proxy_cutoff PROXY_CUTOFF
The distance cutoff to use for the atoms to be considered neighbors.
--epsilon EPSILON The Gaussian cutoff to use in the analytic volume calculation.
--res RES The grid resolution to use for the Gaussian volume calculation.
--margin MARGIN The margin to add to the grid box size for the Gaussian volume calculation.
--no_carbon_radii Disable the use of carbon radii for the overlap calculations.
--color Calculate color scores in addition to shape scores.
--fdef_path FDEF_PATH
The file path to the feature definition file to use for the pharmacophore calculation.
--sort_by SORT_BY The score to sort the final results by.
--write_to_file Write the transformed molecules to a sdf file.
--max_conformers MAX_CONFORMERS
The maximum number of conformers to write for each molecule.
--filename FILENAME The name of the output file to write.
--random_seed RANDOM_SEED
Random seed for conformer generation.
--method {ETDG,ETKDG,ETKDGv2,ETKDGv3}
The method to use for conformer generation (ETDG, ETKDG, or ETKDGv2)
--ff {UFF,MMFF94s,MMFF94s_noEstat}
The force field to use for conformer generation (UFF, MMFF94s, or MMFF94s_noEstat)
--opt_confs Optimize the conformers.
--calc_energy Calculate the energy of the conformers.
--energy_iters ENERGY_ITERS
Number of iterations for energy calculation.
--energy_cutoff ENERGY_CUTOFF
Maximum energy difference (in kcal/mol) to keep a conformer after energy minimization.
--align_confs Align the conformers.
--rms_cutoff RMS_CUTOFF
RMSD cutoff for conformer clustering.
--num_threads NUM_THREADS
Number of threads to use for conformer generation.
I am using ubuntu 22.04 - let me know if this solves your dockerfile install issue.
All the best, Mike
I made a docker implementation in https://github.com/molecularinformatics/roshambo/pull/6, feel free to check it out and let me know if you have any issue.
Thanks for your work on roshambo! Has anyone managed to get roshambo working in a docker image? Here is my attempt:
Dockerfile:
Which yields:
It seems that setup.py attempts to compile the
roshambo/cpaper.cpp
src file usingg++
, but with flags only compatible fornvcc
.Any help is appreciated!