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.

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_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.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:
  • old (str) – Path to the file source.
  • new (str) – Path to the file destination.
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.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)
class schrodinger.utils.fileutils.SeqFormat

Bases: enum.Enum

An enumeration.

__class__

alias of enum.EnumMeta

__members__ = mappingproxy(OrderedDict([('fasta', <SeqFormat.fasta: 1>), ('swissprot', <SeqFormat.swissprot: 2>), ('gcg', <SeqFormat.gcg: 3>), ('embl', <SeqFormat.embl: 4>), ('pir', <SeqFormat.pir: 5>)]))
__module__ = 'schrodinger.utils.fileutils'
embl = 4
fasta = 1
gcg = 3
pir = 5
swissprot = 2
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_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_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.is_pdb_file(filename)

Returns whether the specified filename represents a PDB file.

Parameters:filename (str) – a filename
Returns:Whether the file is a pdb 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_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_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_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_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_cms_file(filename)

Returns True if specified filename represent a CMS file.

Parameters:filename (str) – a filename
Returns:Is this filename a CMS 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.strip_extension(filename)

Return a new file path without extension. Suffixes such as “_pv” and “_epv” are also removed.

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.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_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.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_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_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_mmshare_dir()

Return the path to the local $SCHRODINGER/mmshare-*/ directory

Returns:Path to the “mmshare” directory.
Return type:str
schrodinger.utils.fileutils.get_mmshare_data_dir()

Return the path of the local $SCHRODINGER/mmshare-*/data/ directory.

Returns:Path to the “data” directory.
Return type:str
schrodinger.utils.fileutils.get_mmshare_scripts_dir()

Return the path of the $SCHRODINGER/mmshare-*/python/scripts/ directory.

Returns:Path to the “scripts” directory.
Return type:str
schrodinger.utils.fileutils.get_mmshare_common_dir()

Return the path of the $SCHRODINGER/mmshare-*/python/common/ directory.

Returns:Path to the “common” directory.
Return type:str
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_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_home_dir()
Deprecated:get_directory_path should be used instead.
schrodinger.utils.fileutils.get_appdata_dir()
Deprecated:get_directory_path should be used instead.
schrodinger.utils.fileutils.get_local_appdata_dir()
Deprecated:get_directory_path should be used instead.
schrodinger.utils.fileutils.get_desktop_dir()
Deprecated:get_directory_path should be used instead.
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_userdata_dir()
Deprecated:get_directory_path should be used instead.
schrodinger.utils.fileutils.get_schrodinger_temp_dir()
Deprecated:get_directory_path should be used instead.
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.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
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.

__init__(dirname)

Initialize self. See help(type(self)) for accurate signature.

__enter__()
__exit__(*args)
__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.fileutils', '__doc__': '\n A context manager that carries out commands inside of the specified\n directory and restores the current directory when done.\n ', '__init__': <function chdir.__init__>, '__enter__': <function chdir.__enter__>, '__exit__': <function chdir.__exit__>, '__dict__': <attribute '__dict__' of 'chdir' objects>, '__weakref__': <attribute '__weakref__' of 'chdir' objects>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.utils.fileutils'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

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.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.

class schrodinger.utils.fileutils.tempfilename

Bases: str

static __new__(cls, prefix='tmp', suffix='', temp_dir=None)

A thread-safe replacement for tempfile.mktemp. Creates a temporary file with the given prefix, suffix, and directory and returns its filename. Calling remove will remove the file. Can be used as a context manager, which will remove the file automatically on exit.

Parameters:
  • prefix (str) – Filename prefix
  • suffix (str) – Filename suffix
  • temp_dir (str or None.) – Filename directory path. Defaults to the schrodinger temp directory.
Returns:

The name of the file descriptor, wrapped in a context manager that will remove the file on exit.

__enter__()
__exit__(exc_type, exc_value, traceback)
remove()
__add__

Return self+value.

__class__

alias of builtins.type

__contains__

Return key in self.

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.fileutils', '__new__': <staticmethod object>, '__enter__': <function tempfilename.__enter__>, '__exit__': <function tempfilename.__exit__>, 'remove': <function tempfilename.remove>, '__dict__': <attribute '__dict__' of 'tempfilename' objects>, '__weakref__': <attribute '__weakref__' of 'tempfilename' objects>, '__doc__': None})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__(format_spec) → str

Return a formatted version of S as described by format_spec.

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getitem__

Return self[key].

__getnewargs__()
__gt__

Return self>value.

__hash__

Return hash(self).

__init__

Initialize self. See help(type(self)) for accurate signature.

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__mod__

Return self%value.

__module__ = 'schrodinger.utils.fileutils'
__mul__

Return self*value.n

__ne__

Return self!=value.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__rmod__

Return value%self.

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__sizeof__() → size of S in memory, in bytes
__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

capitalize() → str

Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case.

casefold() → str

Return a version of S suitable for caseless comparisons.

center(width[, fillchar]) → str

Return S centered in a string of length width. Padding is done using the specified fill character (default is a space)

count(sub[, start[, end]]) → int

Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.

encode(encoding='utf-8', errors='strict') → bytes

Encode S using the codec registered for encoding. Default encoding is ‘utf-8’. errors may be given to set a different error handling scheme. Default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

endswith(suffix[, start[, end]]) → bool

Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.

expandtabs(tabsize=8) → str

Return a copy of S where all tab characters are expanded using spaces. If tabsize is not given, a tab size of 8 characters is assumed.

find(sub[, start[, end]]) → int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

format(*args, **kwargs) → str

Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).

format_map(mapping) → str

Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{‘ and ‘}’).

index(sub[, start[, end]]) → int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

isalnum() → bool

Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise.

isalpha() → bool

Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise.

isdecimal() → bool

Return True if there are only decimal characters in S, False otherwise.

isdigit() → bool

Return True if all characters in S are digits and there is at least one character in S, False otherwise.

isidentifier() → bool

Return True if S is a valid identifier according to the language definition.

Use keyword.iskeyword() to test for reserved identifiers such as “def” and “class”.

islower() → bool

Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise.

isnumeric() → bool

Return True if there are only numeric characters in S, False otherwise.

isprintable() → bool

Return True if all characters in S are considered printable in repr() or S is empty, False otherwise.

isspace() → bool

Return True if all characters in S are whitespace and there is at least one character in S, False otherwise.

istitle() → bool

Return True if S is a titlecased string and there is at least one character in S, i.e. upper- and titlecase characters may only follow uncased characters and lowercase characters only cased ones. Return False otherwise.

isupper() → bool

Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise.

join(iterable) → str

Return a string which is the concatenation of the strings in the iterable. The separator between elements is S.

ljust(width[, fillchar]) → str

Return S left-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space).

lower() → str

Return a copy of the string S converted to lowercase.

lstrip([chars]) → str

Return a copy of the string S with leading whitespace removed. If chars is given and not None, remove characters in chars instead.

static maketrans()

Return a translation table usable for str.translate().

If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

partition(sep) -> (head, sep, tail)

Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return S and two empty strings.

replace(old, new[, count]) → str

Return a copy of S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.

rfind(sub[, start[, end]]) → int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

rindex(sub[, start[, end]]) → int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

rjust(width[, fillchar]) → str

Return S right-justified in a string of length width. Padding is done using the specified fill character (default is a space).

rpartition(sep) -> (head, sep, tail)

Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return two empty strings and S.

rsplit(sep=None, maxsplit=-1) → list of strings

Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. If maxsplit is given, at most maxsplit splits are done. If sep is not specified, any whitespace string is a separator.

rstrip([chars]) → str

Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead.

split(sep=None, maxsplit=-1) → list of strings

Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.

splitlines([keepends]) → list of strings

Return a list of the lines in S, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true.

startswith(prefix[, start[, end]]) → bool

Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.

strip([chars]) → str

Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead.

swapcase() → str

Return a copy of S with uppercase characters converted to lowercase and vice versa.

title() → str

Return a titlecased version of S, i.e. words start with title case characters, all remaining cased characters have lower case.

translate(table) → str

Return a copy of the string S in which each character has been mapped through the given translation table. The table must implement lookup/indexing via __getitem__, for instance a dictionary or list, mapping Unicode ordinals to Unicode ordinals, strings, or None. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

upper() → str

Return a copy of S converted to uppercase.

zfill(width) → str

Pad a numeric string S with zeros on the left, to fill a field of the specified width. The string S is never truncated.

class schrodinger.utils.fileutils.TempStructureFile

Bases: schrodinger.utils.fileutils.tempfilename

static __new__(cls, sts)

Creates a temporary file containing a set of structures using the thread-safe implementation of tempfilename.

Parameters:sts (iterable of {structure.Structure}) – structures to write to the temp file
__add__

Return self+value.

__class__

alias of builtins.type

__contains__

Return key in self.

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.fileutils', '__new__': <staticmethod object>, '__doc__': None})
__dir__() → list

default dir() implementation

__enter__()
__eq__

Return self==value.

__exit__(exc_type, exc_value, traceback)
__format__(format_spec) → str

Return a formatted version of S as described by format_spec.

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getitem__

Return self[key].

__getnewargs__()
__gt__

Return self>value.

__hash__

Return hash(self).

__init__

Initialize self. See help(type(self)) for accurate signature.

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__mod__

Return self%value.

__module__ = 'schrodinger.utils.fileutils'
__mul__

Return self*value.n

__ne__

Return self!=value.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__rmod__

Return value%self.

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__sizeof__() → size of S in memory, in bytes
__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

capitalize() → str

Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case.

casefold() → str

Return a version of S suitable for caseless comparisons.

center(width[, fillchar]) → str

Return S centered in a string of length width. Padding is done using the specified fill character (default is a space)

count(sub[, start[, end]]) → int

Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.

encode(encoding='utf-8', errors='strict') → bytes

Encode S using the codec registered for encoding. Default encoding is ‘utf-8’. errors may be given to set a different error handling scheme. Default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

endswith(suffix[, start[, end]]) → bool

Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.

expandtabs(tabsize=8) → str

Return a copy of S where all tab characters are expanded using spaces. If tabsize is not given, a tab size of 8 characters is assumed.

find(sub[, start[, end]]) → int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

format(*args, **kwargs) → str

Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).

format_map(mapping) → str

Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{‘ and ‘}’).

index(sub[, start[, end]]) → int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

isalnum() → bool

Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise.

isalpha() → bool

Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise.

isdecimal() → bool

Return True if there are only decimal characters in S, False otherwise.

isdigit() → bool

Return True if all characters in S are digits and there is at least one character in S, False otherwise.

isidentifier() → bool

Return True if S is a valid identifier according to the language definition.

Use keyword.iskeyword() to test for reserved identifiers such as “def” and “class”.

islower() → bool

Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise.

isnumeric() → bool

Return True if there are only numeric characters in S, False otherwise.

isprintable() → bool

Return True if all characters in S are considered printable in repr() or S is empty, False otherwise.

isspace() → bool

Return True if all characters in S are whitespace and there is at least one character in S, False otherwise.

istitle() → bool

Return True if S is a titlecased string and there is at least one character in S, i.e. upper- and titlecase characters may only follow uncased characters and lowercase characters only cased ones. Return False otherwise.

isupper() → bool

Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise.

join(iterable) → str

Return a string which is the concatenation of the strings in the iterable. The separator between elements is S.

ljust(width[, fillchar]) → str

Return S left-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space).

lower() → str

Return a copy of the string S converted to lowercase.

lstrip([chars]) → str

Return a copy of the string S with leading whitespace removed. If chars is given and not None, remove characters in chars instead.

static maketrans()

Return a translation table usable for str.translate().

If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

partition(sep) -> (head, sep, tail)

Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return S and two empty strings.

remove()
replace(old, new[, count]) → str

Return a copy of S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.

rfind(sub[, start[, end]]) → int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

rindex(sub[, start[, end]]) → int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

rjust(width[, fillchar]) → str

Return S right-justified in a string of length width. Padding is done using the specified fill character (default is a space).

rpartition(sep) -> (head, sep, tail)

Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return two empty strings and S.

rsplit(sep=None, maxsplit=-1) → list of strings

Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. If maxsplit is given, at most maxsplit splits are done. If sep is not specified, any whitespace string is a separator.

rstrip([chars]) → str

Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead.

split(sep=None, maxsplit=-1) → list of strings

Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.

splitlines([keepends]) → list of strings

Return a list of the lines in S, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true.

startswith(prefix[, start[, end]]) → bool

Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.

strip([chars]) → str

Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead.

swapcase() → str

Return a copy of S with uppercase characters converted to lowercase and vice versa.

title() → str

Return a titlecased version of S, i.e. words start with title case characters, all remaining cased characters have lower case.

translate(table) → str

Return a copy of the string S in which each character has been mapped through the given translation table. The table must implement lookup/indexing via __getitem__, for instance a dictionary or list, mapping Unicode ordinals to Unicode ordinals, strings, or None. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

upper() → str

Return a copy of S converted to uppercase.

zfill(width) → str

Pad a numeric string S with zeros on the left, to fill a field of the specified width. The string S is never truncated.

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
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 over str) – Iterable over file names to be added to the archive.
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.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.change_working_directory(folder)

A context manager to temporarily change the working directory to folder :param folder: the folder that becomes the working directory :type folder: str

schrodinger.utils.fileutils.in_temporary_directory()

A context manager for executing a block of code in a temporary directory.