htmd.util module#

htmd.util.assertSameAsReferenceDir(compareDir, outdir='.')#

Check that files in a reference directory match those in an output directory.

Subdirectories are compared recursively. Raises an exception if any file is missing or its content differs.

Parameters:
  • compareDir (str) – Path to the reference directory.

  • outdir (str) – Path to the output directory to compare against the reference.

Raises:

Exception – If any file is missing, has differing content, or cannot be compared.

Return type:

None

htmd.util.diffMolecules(mol1, mol2, sel=None)#

Check that name, resname, resid, and insertion codes match between two molecules.

Coordinates are not checked.

Parameters:
  • mol1 (Molecule) – First structure to compare.

  • mol2 (Molecule) – Second structure to compare.

  • sel (str | ndarray | None) – An atom selection string, a boolean mask, or an integer index array (see Molecule.atomselect). If provided, only the selected atoms are compared.

Returns:

diff – A list of differences as human-readable strings. Empty if the structures are equal.

Return type:

list

Examples

>>> m = Molecule("3PTB")
>>> m2 = m.copy()
>>> m2.set("resname", "HIE", "resid 91")
>>> diffMolecules(m, m2, sel="name CA")
['CA   HIS    91     vs   CA   HIE    91  ']
htmd.util.ensurelist(tocheck, tomod=None)#

Convert np.ndarray and scalars to lists.

Lists and tuples are left as is. If a second argument is given, the type check is performed on the first argument, and the second argument is converted.

Parameters:
  • tocheck (object) – The value whose type is inspected to decide whether conversion is needed.

  • tomod (object, optional) – The value to convert. If None, tocheck is converted instead.

Returns:

resulttomod (or tocheck) as a list.

Return type:

list

htmd.util.getPdbStrings(mol, sel=None, onlyAtom=True)#

Return the PDB corresponding to a molecule and selection as a list of strings.

Parameters:
  • mol (Molecule) – The Molecule object.

  • sel (str | ndarray | None) – An atom selection string, a boolean mask, or an integer index array (see Molecule.atomselect) for what to output.

  • onlyAtom (bool) – If True, only ATOM/HETATM records are returned.

Returns:

lines – PDB record lines as strings.

Return type:

list

Examples

>>> m = Molecule("3PTB")
>>> getPdbStrings(m, "resname BEN")
['HETATM    1  C1  BEN A   1      -1.853  14.311  16.658  1.00 19.86      1    C  ',
 'HETATM    2  C2  BEN A   1      -2.107  15.653  16.758  1.00 19.86      1    C  ',
 'HETATM    3  C3  BEN A   1      -1.774  16.341  17.932  1.00 19.86      1    C  ',
 'HETATM    4  C4  BEN A   1      -1.175  15.662  19.005  1.00 19.86      1    C  ',
 'HETATM    5  C5  BEN A   1      -0.914  14.295  18.885  1.00 19.86      1    C  ',
 'HETATM    6  C6  BEN A   1      -1.257  13.634  17.708  1.00 19.86      1    C  ',
 'HETATM    7  C   BEN A   1      -2.193  13.627  15.496  1.00 19.86      1    C  ',
 'HETATM    8  N1  BEN A   1      -2.797  14.235  14.491  1.00 19.86      1    N  ',
 'HETATM    9  N2  BEN A   1      -1.762  12.391  15.309  1.00 19.86      1    N  ']
htmd.util.tempname(suffix='', create=False)#

Return a path to a temporary file, optionally creating it on disk.

Parameters:
  • suffix (str) – File name suffix (including the dot, e.g. ".pdb").

  • create (bool) – If True, the file is created on disk. If False, the name is reserved but the file is not kept.

Returns:

name – Absolute path to the temporary file.

Return type:

str

htmd.util.testDHFR()#