schrodinger.utils.fileutils module¶
A module of file utilities to deal with common file issues.
NOTE: This module is used in scripts that need to be able to run without a Schrodinger license, and therefore can’t depend on the pymmlibs.
The force_remove and force_rename functions deal with the fact that os.remove() and os.rename() don’t work on Windows if write permissions are not enabled.
-
class
schrodinger.utils.fileutils.
SeqFormat
¶ Bases:
enum.Enum
-
embl
= 4¶
-
fasta
= 1¶
-
gcg
= 3¶
-
pir
= 5¶
-
swissprot
= 2¶
-
-
class
schrodinger.utils.fileutils.
TempStructureFile
¶
-
schrodinger.utils.fileutils.
cat
(source_filenames, dest_filename)¶ Concatenate the contents of the source files, writing them to a destination file. All files are specified by name. If source_filenames is an empty list, an empty file is produced.
Parameters: - source_filenames (sequence of str) – input files
- dest_filename (str) – destination file
-
class
schrodinger.utils.fileutils.
chdir
(dirname)¶ Bases:
object
A context manager that carries out commands inside of the specified directory and restores the current directory when done.
-
schrodinger.utils.fileutils.
create_hard_link
(source, link_name)¶ Create a hard link pointing to source named link_name.
On Windows, uses CreateHardLinkA() and will raise RuntimeError() on failure.
On other OSes uses os.link(), and will raise OSError on failure.
-
schrodinger.utils.fileutils.
force_remove
(*args)¶ Remove each file in ‘args’ in a platform independent way without an exception, regardless of presence of the file or the lack of write permission.
Parameters: args (str) – the pathname for the files to remove
-
schrodinger.utils.fileutils.
force_rename
(old, new)¶ Rename a file, even if a file at the new name exists, and even if that file doesn’t have write permission, and even if old and new are on different devices.
Parameters: Note: Renaming may not be an atomic operation. If the ‘new’ file exists then it is first removed then renamed in two operations. Similarly, if old and new are not on the same device then the file is copied to ‘new’ then the ‘old’ file is removed.
-
schrodinger.utils.fileutils.
force_rmtree
(dirname, ignore_errors=False)¶ Remove the directory ‘dirname’, using force_remove to remove any difficult to remove files or sub-directories.
Parameters: dirname (str) – the directory to remove
-
schrodinger.utils.fileutils.
get_appdata_dir
()¶ Deprecated: get_directory_path should be used instead.
-
schrodinger.utils.fileutils.
get_basename
(filename)¶ Returns the final component of specified path name minus the extension. Suffixes such as “_pv” and “_epv” are also stripped.
-
schrodinger.utils.fileutils.
get_desktop_dir
()¶ Deprecated: get_directory_path should be used instead.
-
schrodinger.utils.fileutils.
get_directory
(which_directory)¶ Deprecated: Because this function behaves in a non-standard way by returning an mmlib status, get_directory_path
is preferred.
-
schrodinger.utils.fileutils.
get_directory_path
(which_directory)¶ This function returns the schrodinger specific directory.
If an invalid which_directory is specified, then a TypeError is thrown.
Valid directories are:
- HOME : To get user’s home dir
- APPDATA : To get the Schrodinger application shared data dir
- LOCAL_APPDATA : To get the Schrodinger application local data dir
- USERDATA : To get user’s data dir
- TEMP : To get default temporary data dir
- DESKTOP : To get user’s desktop dir
- DOCUMENTS : To get user’s ‘My Documents’ dir
- NETWORK : To get user’s ‘My Network places’ dir (only for Windows)
Return type: str Returns: Directory path
-
schrodinger.utils.fileutils.
get_files_from_folder
(folder_abs_path)¶ Walk through a folder, find all files inside it.
Parameters: folder_abs_path (string) – folder path Return type: list of tuple Returns: each tuple contains: absolute path of a file, and a relative path that the file will be transferred to.
-
schrodinger.utils.fileutils.
get_home_dir
()¶ Deprecated: get_directory_path should be used instead.
-
schrodinger.utils.fileutils.
get_jobname
(filename)¶ Returns a job name derived from the specified filename. Same as get_basename(), except that illegal characters are removed.
-
schrodinger.utils.fileutils.
get_local_appdata_dir
()¶ Deprecated: get_directory_path should be used instead.
Return the path of the $SCHRODINGER/mmshare-*/python/common/ directory.
Returns: Path to the “common” directory. Return type: str
Return the path of the local $SCHRODINGER/mmshare-*/data/ directory.
Returns: Path to the “data” directory. Return type: str
Return the path to the local $SCHRODINGER/mmshare-*/ directory
Returns: Path to the “mmshare” directory. Return type: str
Return the path of the $SCHRODINGER/mmshare-*/python/scripts/ directory.
Returns: Path to the “scripts” directory. Return type: str
-
schrodinger.utils.fileutils.
get_mydocuments_dir
()¶ Deprecated: get_directory_path should be used instead.
-
schrodinger.utils.fileutils.
get_mynetworkplaces_dir
()¶ Deprecated: get_directory_path should be used instead.
-
schrodinger.utils.fileutils.
get_name_filter
(name_mapping)¶ Create filename filters for QFileDialog
Parameters: name_mapping (dict(list(str))) – Mapping between category name and list of file types (must be keys of EXTENSIONS
)Returns: List of filename filters Return type: list(str)
-
schrodinger.utils.fileutils.
get_next_filename
(path, midfix, zfill_width=0)¶ Return next filename in series <root><midfix><number>.<ext>.
Given a path (absolute or relative) to a filename, return the next filename in the sequence implied by path and midfix. For example, with a path of /full/path/to/foo.mae, path/to/foo.mae or foo.mae and a midfix of ‘-‘, this function will return “foo-3.mae” if file foo-2.mae (and no higher-numbered foo-*.mae) is present. It will return foo-1.mae if no file named foo-<number>.mae is present.
This function differs from next_filename_prefix() in that here, only files with the specified extension are searched, and the next full filename is retured.
The search is case sensitive or not depending on the semantics of the file system. The leading directory of the path, if any, is included in the return value.
Usage note: You might use this when you are expecting to update only a single file: the one whose filename is given in the path. For example, you are exporting structures to a .mae file and you want to pick a non-conflicting name based on a user’s filename specification.
-
schrodinger.utils.fileutils.
get_next_filename_prefix
(path, midfix, zfill_width=0)¶ Return next filename prefix in series <root><midfix><number>.
Given a path (absolute or relative) to a filename or filename prefix, return the next prefix in the sequence implied by path and midfix. For example, with a path of /full/path/to/foo.mae, path/to/foo.mae or foo.mae, or /full/path/to/foo, path/to/foo or foo, and a midfix of ‘-‘, this function will return “foo-3” if any file whose prefix foo-2 (and no higher-numbered foo-*) is present. It will return foo-1 if no file whose prefix is foo-<number> is present. The net effect is that any file-name extension in the path argument will be ignored.
This function differs from next_filename() in that here, all files sharing the prefix contained in the path are searched, regardless of extension, and the next filename prefix is returned.
The search is case sensitive or not depending on the semantics of the file system. The leading directory of the path, if any, is included in the return value.
Usage note: you might use this when the filename prefix could be exhibited by many files and you don’t want to overwrite any of them. For example, you are starting up a job which will create many files with the same prefix.
-
schrodinger.utils.fileutils.
get_pymol_cmd
(use_x11=False)¶ Get a cmd list for launching Pymol. This may include extra platform- specific arguments.
Parameters: use_x11 (bool) – if True causes -m to be added to the launch command on Mac Returns: a cmd list with the executable as first element and any other options following it. Return type: list
-
schrodinger.utils.fileutils.
get_schrodinger_temp_dir
()¶ Deprecated: get_directory_path should be used instead.
-
schrodinger.utils.fileutils.
get_sequence_file_format
(filename)¶ Return the format of a sequence file, based on the filename extension. None is returned if the file extension is not recognized.
Parameters: filename (str) – Filename to detect format Returns: File format or None if not recognized Return type: str or None
-
schrodinger.utils.fileutils.
get_structure_file_format
(filename)¶ Return the format of a structure file, based on the filename extension. None is returned if the file extension is not recognized.
Parameters: filename (str) – Filename to detect format Returns: File format or None if not recognized Return type: str or None
-
schrodinger.utils.fileutils.
get_userdata_dir
()¶ Deprecated: get_directory_path should be used instead.
-
schrodinger.utils.fileutils.
is_csv_file
(filename)¶ Returns True if specified filename represents a CSV file.
Parameters: filename (str) – a filename Returns: Is this filename a csv file? Return type: bool
-
schrodinger.utils.fileutils.
is_gzipped_structure_file
(filename)¶ Returns True if the filename represents a file that is GZipped and it has a recognized structure extension.
Parameters: filename (str) – a filename Returns: Is this filename a gzipped structure file? Return type: bool
-
schrodinger.utils.fileutils.
is_hypothesis_file
(filename)¶ Returns True if specified filename represents a Phase hypothesis file. The .phypo extension corresponds to a gzipped Maestro file containing a single ct which is a Phase hypothesis.
Parameters: filename (str) – a filename Returns: Is this filename a Phase hypothesis file? Return type: bool
-
schrodinger.utils.fileutils.
is_maestro_file
(filename)¶ Returns True if specified filename represents a Maestro file.
Parameters: filename (str) – a filename Returns: Is this filename a maestro file? Return type: bool
-
schrodinger.utils.fileutils.
is_poseviewer_file
(filename)¶ Returns True if specified filename represents a Maestro PoseViewer file. Checks if the filename ends with _pv.mae, _pv.maegz, _pv.mae.gz, etc.
Parameters: filename (str) – a filename Returns: Is this filename a PV file? Return type: bool
-
schrodinger.utils.fileutils.
is_sd_file
(filename)¶ Returns True if specified filename represents a SD file.
Parameters: filename (str) – a filename Returns: Is this filename an SD file? Return type: bool
-
schrodinger.utils.fileutils.
is_smiles_file
(filename)¶ Returns True if specified filename represents a Smiles file.
Parameters: filename (str) – a filename Returns: Is this filename a smiles file? Return type: bool
-
schrodinger.utils.fileutils.
is_valid_jobname
(jobname)¶ Returns True if specified job name is valid, does not contain any illegal characters, and does not start with “.”.
-
schrodinger.utils.fileutils.
locate_pymol
()¶ Find the executable or script we use to launch PyMOL.
Return type: str or None Returns: The pymol launch command or None if PyMOL was not found
-
schrodinger.utils.fileutils.
mkdir_p
(path, *mode)¶ Like os.makedirs, create a directory, including intermediate-level directories if necessary. But unlike os.makedirs, don’t complain if the directory already exists. The name of this function comes from the POSIX “mkdir -p” shell utility, which behaves the same way.
-
schrodinger.utils.fileutils.
on_same_drive_letter
(path_a, path_b)¶ Returns true if path_a and path_b are on the same driveletter. On systems without drive letters, always return True.
-
schrodinger.utils.fileutils.
splitext
(p)¶ Split the extension from a pathname. Returns “(root, ext)”. Equivalent to os.path.splitext(), except that for gzip compressed files, such as *.mae.gz files, “.mae.gz” is split off instead of “.gz”. *.sdf.gz, *.sd.gz, *.mol.gz
Parameters: p (str) – a pathname Returns: The root filename and the file extension. Return type: tuple(str, str)
-
schrodinger.utils.fileutils.
tar_files
(tarname, mode, files)¶ Writes files to tar archive.
Parameters: - tarname (
str
) – Tar file name. - mode (
str
) – File open mode. - files (
iterable
overstr
) – Iterable over file names to be added to the archive.
- tarname (