Exemple #1
0
def test_piyzaz_replication_2_3_1_without_centering():
    """Tests replicating PIYZAZ (CCDC) 2x3x1 without centering.
    Reference structure is generated using Mercury software."""
    piyzaz = Molecule(read=piyzaz111_xyz)
    piyzaz.set_cell(piyzaz_cell_parameters)
    piyzaz231 = piyzaz.replicate([2, 3, 1], center=False)

    piyzaz231_ref = Molecule(read=piyzaz231_xyz)
    assert np.allclose(piyzaz231.coordinates, piyzaz231_ref.coordinates)
    assert set(piyzaz231.atoms) == set(piyzaz231_ref.atoms)
    assert piyzaz231.cell.a == piyzaz.cell.a * 2
    assert piyzaz231.cell.b == piyzaz.cell.b * 3
    assert piyzaz231.cell.c == piyzaz.cell.c * 1
    assert piyzaz231.cell.alpha == piyzaz.cell.alpha
    assert piyzaz231.cell.beta == piyzaz.cell.beta
    assert piyzaz231.cell.gamma == piyzaz.cell.gamma
Exemple #2
0
def test_benzene_read_and_get_topology():
    benzene = Molecule(read=benzene_xyz)
    benzene.get_topology()

    expected_bonds = [(0, 1), (0, 2), (0, 10), (2, 3), (2, 4), (4, 5), (4, 6),
                      (6, 7), (6, 8), (8, 9), (8, 10), (10, 11)]
    assert benzene.bonds == expected_bonds

    expected_angles = [(0, 2, 3), (0, 2, 4), (0, 10, 8), (0, 10, 11),
                       (1, 0, 2), (1, 0, 10), (2, 0, 10), (2, 4, 5), (2, 4, 6),
                       (3, 2, 4), (4, 6, 7), (4, 6, 8), (5, 4, 6), (6, 8, 9),
                       (6, 8, 10), (7, 6, 8), (8, 10, 11), (9, 8, 10)]
    assert benzene.angles == expected_angles

    expected_dihedrals = [(0, 2, 4, 5), (0, 2, 4, 6), (0, 8, 10, 6),
                          (0, 8, 10, 9), (1, 0, 2, 3), (1, 0, 2, 4),
                          (1, 0, 10, 8), (1, 0, 10, 11), (2, 0, 10, 8),
                          (2, 0, 10, 11), (2, 4, 6, 7), (2, 4, 6, 8),
                          (3, 0, 2, 10), (3, 2, 4, 5), (3, 2, 4, 6),
                          (4, 0, 2, 10), (4, 6, 8, 9), (4, 6, 8, 10),
                          (5, 4, 6, 7), (5, 4, 6, 8), (6, 8, 10, 11),
                          (7, 6, 8, 9), (7, 6, 8, 10), (9, 8, 10, 11)]
    assert benzene.dihedrals == expected_dihedrals

    expected_impropers = [(0, 2, 3, 4), (0, 10, 8, 11), (1, 0, 2, 10),
                          (2, 0, 1, 10), (2, 4, 5, 6), (3, 2, 0, 4),
                          (4, 2, 0, 3), (4, 6, 7, 8), (5, 4, 2, 6),
                          (6, 4, 2, 5), (6, 8, 9, 10), (7, 6, 4, 8),
                          (8, 6, 4, 7), (8, 10, 0, 11), (9, 8, 6, 10),
                          (10, 0, 1, 2), (10, 8, 6, 9), (11, 10, 0, 8)]
    assert benzene.impropers == expected_impropers
Exemple #3
0
def test_piyzaz_replication_4_4_4_without_centering():
    """Tests replicating PIYZAZ (CCDC) 4x4x4 without centering.
    Reference structure is generated using Mercury software."""
    piyzaz = Molecule(read=piyzaz111_xyz)
    piyzaz.set_cell(piyzaz_cell_parameters)
    piyzaz444 = piyzaz.replicate([4, 4, 4], center=False)

    piyzaz444_ref = Molecule(read=piyzaz444_xyz)
    assert np.allclose(piyzaz444.coordinates, piyzaz444_ref.coordinates)
    assert set(piyzaz444.atoms) == set(piyzaz444_ref.atoms)
    assert piyzaz444.cell.a == piyzaz.cell.a * 4
    assert piyzaz444.cell.b == piyzaz.cell.b * 4
    assert piyzaz444.cell.c == piyzaz.cell.c * 4
    assert piyzaz444.cell.alpha == piyzaz.cell.alpha
    assert piyzaz444.cell.beta == piyzaz.cell.beta
    assert piyzaz444.cell.gamma == piyzaz.cell.gamma
Exemple #4
0
def test_molecule_center_calculation_of_benzene():
    """Tests molecule center for benzene"""
    benzene = Molecule(read=benzene_xyz)
    benzene_com = benzene.get_center()              # Center of mass
    benzene_cog = benzene.get_center(mass=False)    # Geometric center
    assert np.allclose(get_molecule_center(benzene.atoms, benzene.coordinates), [0, 0, 0])
    assert np.allclose(benzene_com, [0, 0, 0])
    assert np.allclose(benzene_com, benzene_cog)
Exemple #5
0
def connect_wheel(opts):
    """
    Connect wheel molecule to selected atom position.
    The wheel molecule must have a connection site (Xc) and alignmen site (Xa) to specify connectivity.
    The selected wheel molecule is added to selected atom by aligning the vector of the wheel.
    """
    selected = [idx for idx, atm in enumerate(opts['cjson']['atoms']['selected']) if atm]
    if len(selected) == 1:
        # Get chassi coordinates and bonds
        coords = np.array(opts['cjson']['atoms']['coords']['3d'])
        connections = opts['cjson']['bonds']['connections']['index']
        atoms = [periodictable.elements[i].symbol for i in opts['cjson']['atoms']['elements']['number']]
        chassi = Molecule(atoms=atoms, coordinates=np.array(coords).reshape((int(len(coords) / 3)), 3))

        # Get connection site for the chassis
        selected_cidx = int(selected[0] * 3)
        selected_coors = coords[selected_cidx:selected_cidx + 3]

        # Find atom connected to the selected atom
        bond_idx = connections.index(selected[0])
        if bond_idx % 2 == 0:
            bond_idx += 1
        else:
            bond_idx -= 1
        bond_idx = int(connections[bond_idx] * 3)

        # Get vector btw selected atom and atom connected to it
        v_chassi = selected_coors - np.array(coords[bond_idx:bond_idx + 3])

        # Read wheel molecule information
        wheel = read_wheel(opts['wheel'])

        # Align the wheel with chassis connection vector
        v_wheel = wheel.coordinates[wheel.alignment_site] - wheel.coordinates[wheel.connection_site]
        wheel.align(v_wheel, v_chassi)

        # Translate the wheel to match dummy coor with selected coor
        v_trans = selected_coors - wheel.coordinates[wheel.connection_site]
        wheel.translate(v_trans)

        # Adjust bond distance
        v_bond = wheel.coordinates[wheel.connection_site] - wheel.coordinates[wheel.alignment_site]
        d_bond = np.linalg.norm(v_bond)
        v_bond = v_bond - v_bond / d_bond * opts['d']
        wheel.translate(v_bond)

        # Remove dummy atoms for alignment and connection sites
        wheel.coordinates = np.delete(wheel.coordinates, [wheel.connection_site, wheel.alignment_site], axis=0)
        wheel.atoms = np.delete(wheel.atoms, [wheel.connection_site, wheel.alignment_site])
        if not opts['append']:
            wheel += chassi

        wheel = mol2xyz(wheel)
    else:
        print('Only 1 atom should be selected!')
        wheel = None

    return wheel
Exemple #6
0
def test_diatomic_dummy_molecule_rotation_around_global_axis():
    """ Test dummpy molecule for 90 degree rotations on global z-axis """
    mol = Molecule()
    mol.atoms = ['C'] * 2
    mol.coordinates = np.array([[1, 0, 0], [0, 1, 0]])
    mol.rotate(([0, 0, 0], [0, 0, 1]), np.pi / 2, center=False)
    assert np.allclose(mol.coordinates, [[0, 1, 0], [-1, 0, 0]])
    mol.rotate(([0, 0, 0], [0, 0, 1]), np.pi, center=False)
    assert np.allclose(mol.coordinates, [[0, -1, 0], [1, 0, 0]])
Exemple #7
0
def test_benzene_alignment():
    """ Tests alinging benzene from xy plane to xz plane """
    benzene = Molecule(read=benzene_xyz)
    v_align = [0, 0, 1]
    v_benzene = benzene.coordinates[0] - benzene.coordinates[6]
    benzene.align(v_benzene, v_align)
    # Check if the benzene vector is parallel to z-axis
    assert np.allclose(
        np.cross(benzene.coordinates[0] - benzene.coordinates[6], v_align),
        [0, 0, 0])
def test_write_cif_PIYZAZ():
    """
    Tests writing cif formatted molecule file
    File comparison tests are OS dependent, they should only work in UNIX but not Windows.
    """
    piyzaz = Molecule(atoms=piyzaz_atoms, coordinates=piyzaz_coors)
    test_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'piyzaz_test.cif')
    piyzaz.write(test_file, cell=piyzaz_cell_parameters, header='piyzaz')
    assert filecmp.cmp(piyzaz_cif, test_file)
    os.remove(test_file)
Exemple #9
0
def test_piyzaz_replication_2_2_2_with_centering():
    """Tests replicating PIYZAZ (CCDC) 2x2x2 with centering.
    Reference structure is generated using Mercury software."""
    piyzaz = Molecule(read=piyzaz111_xyz)
    piyzaz.set_cell(piyzaz_cell_parameters)
    piyzaz222 = piyzaz.replicate([2, 2, 2], center=True)

    # Move the reference structure so that it's centered to original cell position
    piyzaz222_ref = Molecule(read=piyzaz222_xyz)
    transvec = np.sum(piyzaz.cell.vectors, axis=0) * -1 / 2
    piyzaz222_ref.translate(transvec)
    assert np.allclose(piyzaz222.coordinates, piyzaz222_ref.coordinates)
    assert set(piyzaz222.atoms) == set(piyzaz222_ref.atoms)
    assert piyzaz222.cell.a == piyzaz.cell.a * 2
    assert piyzaz222.cell.b == piyzaz.cell.b * 2
    assert piyzaz222.cell.c == piyzaz.cell.c * 2
    assert piyzaz222.cell.alpha == piyzaz.cell.alpha
    assert piyzaz222.cell.beta == piyzaz.cell.beta
    assert piyzaz222.cell.gamma == piyzaz.cell.gamma
def test_read_xyz_benzene_molecule():
    """Tests reading xyz formatted molecule file"""
    benzene = Molecule(read=benzene_xyz)
    assert len(benzene) == 12
    assert len(benzene.atoms) == 12
    assert len(benzene.coordinates) == 12
    assert benzene.header == 'benzene'
    for atom, ref_atom in zip(benzene.atoms, benzene_atoms):
        assert atom == ref_atom
    assert np.allclose(benzene.coordinates, benzene_coors)
def test_write_pdb_benzene_molecule_with_bonds():
    """
    Tests writing pdb formatted molecule file with bonds.
    File comparison tests are OS dependent, they should only work in UNIX but not Windows.
    """
    benzene = Molecule(atoms=benzene_atoms, coordinates=benzene_coors)
    test_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'benzene_bonds_test.pdb')
    benzene.write(test_file, bonds=True, header='benzene')
    assert filecmp.cmp(benzene_bonds_pdb, test_file)
    os.remove(test_file)
Exemple #12
0
def test_single_atom_reflection_xy_plane():
    mol = Molecule(atoms=['C'], coordinates=np.array([[0, 0, 1]]))
    mol.reflect('xy')
    assert np.allclose(mol.coordinates, [[0, 0, -1]])
    mol.reflect('xy')
    assert np.allclose(mol.coordinates, [[0, 0, 1]])
    mol.reflect('xy', translate=5)
    assert np.allclose(mol.coordinates, [[0, 0, -6]])
    mol.reflect('xy', translate=5)
    assert np.allclose(mol.coordinates, [[0, 0, 1]])
def test_trajectory_append_molecule():
    """Tests appending molecule to trajectory"""
    benzene_traj = Trajectory(read=benzene_traj_x)
    n_frames = len(benzene_traj)
    benzene_mol = Molecule(read=benzene_xyz)
    benzene_traj.append(benzene_mol)
    assert len(benzene_traj) == n_frames + 1
    assert benzene_traj.atoms.shape[0] == n_frames + 1
    assert benzene_traj.atoms.shape[1] == len(benzene_mol)
    assert benzene_traj.coordinates.shape[0] == n_frames + 1
    assert benzene_traj.coordinates.shape[1] == len(benzene_mol)
Exemple #14
0
def test_write_xyz_benzene_molecule():
    """
    Tests reading xyz formatted molecule file.
    File comparison tests are OS dependent, they should only work in UNIX but not Windows.
    """
    benzene = Molecule(atoms=benzene_atoms, coordinates=benzene_coors)
    test_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                             'benzene_test.xyz')
    benzene.write(test_file, header='benzene')
    assert filecmp.cmp(benzene_xyz, test_file)
    os.remove(test_file)
Exemple #15
0
def test_benzene_reflection_should_not_change_bonding():
    mol = Molecule(read=benzene_xyz)
    mol.reflect('xy')
    mol.get_bonds()
    assert np.allclose(mol.bonds, benzene_bonds)
    mol.reflect('yz')
    mol.get_bonds()
    assert np.allclose(mol.bonds, benzene_bonds)
    mol.reflect('xz')
    mol.get_bonds()
    assert np.allclose(mol.bonds, benzene_bonds)
Exemple #16
0
def test_benzene_addition():
    """Tests molecular addition of two benzenes"""
    benzene = Molecule(read=benzene_xyz)
    benzene2 = benzene + benzene
    assert len(benzene2.atoms) == 2 * len(benzene.atoms)
    assert len(benzene2.coordinates) == 2 * len(benzene.coordinates)
    assert np.allclose(benzene2.coordinates[:12, :], benzene.coordinates)
    assert np.allclose(benzene2.coordinates[12:, :], benzene.coordinates)
    for atom, ref_atom in zip(benzene2.atoms[12:], benzene.atoms):
        assert atom == ref_atom
    for atom, ref_atom in zip(benzene2.atoms[:12], benzene.atoms):
        assert atom == ref_atom
    assert benzene2.name == 'benzene+benzene'
Exemple #17
0
def test_centering_benzene_molecule_to_given_coordinates():
    """Tests molecule center for benzene"""
    benzene = Molecule(read=benzene_xyz)
    benzene.center([5, 0, -5])
    assert np.allclose(benzene.get_center(), [5, 0, -5])
    benzene.center()
    assert np.allclose(benzene.get_center(), [0, 0, 0])
    benzene.translate([0, 0, 7])
    assert np.allclose(benzene.get_center(), [0, 0, 7])
    benzene.rotate(([0, 0, 0], [0, 1, 0]), np.pi / 2)
    assert np.allclose(benzene.get_center(), [7, 0, 0])
    benzene.rotate(([0, 0, 0], [0, 1, 0]), np.pi / 2, center=True)
    assert np.allclose(benzene.get_center(), [7, 0, 0])
Exemple #18
0
def type_mof(filename, output_dir, ff="uff", output_files=True):

    obconversion = OBConversion()
    obconversion.SetInAndOutFormats("cif", "xyz")
    obmol = OBMol()

    # Read MOF file and unit cell and write xyz file
    obconversion.ReadFile(obmol, filename)
    unitcell = openbabel.toUnitCell(obmol.GetData(openbabel.UnitCell))
    uc = [
        unitcell.GetA(),
        unitcell.GetB(),
        unitcell.GetC(),
        unitcell.GetAlpha(),
        unitcell.GetBeta(),
        unitcell.GetGamma()
    ]
    obconversion.WriteFile(obmol, 'mof_tmp.xyz')

    # Replicate unit cell using angstrom
    mol = Molecule(read='mof_tmp.xyz')
    mol.set_cell(uc)
    n_atoms = len(mol.atoms)

    mol333 = mol.replicate([3, 3, 3], center=True)
    print(mol333.cell)
    mol333.write('mof333.cif', cell=mol333.cell.to_list())

    # Type FF
    obconversion.ReadFile(obmol, 'mof333.cif')
    ff = OBForceField.FindForceField("UFF")
    if not ff.Setup(obmol):
        print("Error: could not setup force field")
    ff.GetAtomTypes(obmol)

    # Get atom types for the middle cell
    types = []
    for atom_idx, obatom in enumerate(OBMolAtomIter(obmol)):
        if atom_idx >= n_atoms * 13 and atom_idx < n_atoms * 14:
            ff_atom_type = obatom.GetData("FFAtomType").GetValue()
            types.append(ff_atom_type)

    if output_files:
        mof_name = os.path.splitext(os.path.basename(filename))[0]
        with open(os.path.join(output_dir, mof_name + "-obabel.log"),
                  'w') as f:
            f.write("NOTE: types order is the same as the CIF input file.\n")
            f.write("types= %s" % str(types))

    uniq_types = sorted(set(types))
    return [str(i) for i in uniq_types]
Exemple #19
0
def test_trajectory_from_molecule():
    """Tests converting Molecule to Trajectory object"""
    benzene = Molecule(read=benzene_xyz)
    benzene_traj = Trajectory(molecule=benzene)
    assert len(benzene_traj) == 1
    assert benzene_traj.name == 'benzene'
    assert np.shape(benzene_traj.coordinates) == (1, 12, 3)
    assert np.shape(benzene_traj.atoms) == (1, 12)

    # Test atom names are read correctly
    for frame in benzene_traj:
        assert len(frame.coordinates) == 12
        for atom, ref_atom in zip(frame.atoms, benzene.atoms):
            assert atom == ref_atom
Exemple #20
0
def setup_lammps(opts):
    """Write LAMMPS simulation files."""
    # Read structure information
    coords = np.array(opts['cjson']['atoms']['coords']['3d'])
    atoms = [
        periodictable.elements[i].symbol
        for i in opts['cjson']['atoms']['elements']['number']
    ]
    nanocar = Molecule(atoms=atoms,
                       coordinates=np.array(coords).reshape(
                           (int(len(coords) / 3)), 3))
    opts['box_x'], opts['box_y'], opts[
        'box_z'] = opts['box_x'] * 10, opts['box_y'] * 10, opts['box_z'] * 10
    nanocar.set_cell([opts['box_x'], opts['box_y'], opts['box_z'], 90, 90, 90])
    nanocar.center([opts['box_x'] / 2, opts['box_y'] / 2, opts['box_z'] / 2])
    if not os.path.isdir(opts['dir']):
        # try removing the last part of the path (a file)
        parent = (Path(opts['dir']).parent.absolute())
        if not os.path.isdir(parent):
            opts['dir'] = PLUGIN_DIR
            print('Directory not found! Using plug-in directory -> %s' %
                  PLUGIN_DIR)
        else:
            opts['dir'] = parent
    data_file = os.path.join(opts['dir'], 'data.nanocar')
    write_data_file(data_file, nanocar)

    # Write input file
    surface_info = read_surface_info()
    surface_ids = surface_info['id']
    surface_atoms = surface_ids[1] - surface_ids[0]
    num_atoms = len(nanocar.atoms)
    if surface_ids[0] == 1:
        mol_ids = [num_atoms - surface_atoms, num_atoms]
    else:
        mol_ids = [1, num_atoms - surface_atoms - 1]
    input_file = os.path.join(opts['dir'], 'in.nanocar')
    inp_parameters = {
        'sim_length': opts['sim_length'],
        'ts': opts['timestep'],
        'mol_ids': mol_ids,
        'surface_ids': surface_ids,
        'T': 300
    }
    write_input_file(input_file, nanocar, inp_parameters)
Exemple #21
0
    def __getitem__(self, i):
        """
        Indexing method.
        Returns a Molecule object for given index (frame).
        Returns a Trajectory object if used as slicing.

        """
        if isinstance(i, slice):
            indices = range(len(self))[i.start:i.stop:i.step]
            if len(indices) == 0:
                return []
            else:
                new_traj = Trajectory(molecule=self[indices[0]])
                for j in indices[1:]:
                    new_traj.append(self[j])
                return new_traj
        else:
            return Molecule(atoms=self.atoms[i], coordinates=self.coordinates[i])
Exemple #22
0
"""
--- Ångström ---
Tests bond, angle, dihedral estimation for Molecule class.
"""
from angstrom import Molecule
import os

benzene_xyz = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                           'benzene.xyz')
ethane = Molecule(atoms=['H', 'C', 'H', 'H', 'C', 'H', 'H', 'H'],
                  coordinates=[[1.185080, -0.003838, 0.987524],
                               [0.751621, -0.022441, -0.020839],
                               [1.166929, 0.833015, -0.569312],
                               [1.115519, -0.932892, -0.514525],
                               [-0.751587, 0.022496, 0.020891],
                               [-1.166882, -0.833372, 0.568699],
                               [-1.115691, 0.932608, 0.515082],
                               [-1.184988, 0.004424, -0.987522]])


def test_ethane_should_have_seven_bonds():
    expected_bonds = [(0, 1), (1, 2), (1, 3), (1, 4), (4, 5), (4, 6), (4, 7)]
    ethane.get_bonds()
    assert ethane.bonds == expected_bonds


def test_ethane_should_have_twelve_angles():
    expected_angles = [(0, 1, 2), (0, 1, 3), (0, 1, 4), (1, 4, 5), (1, 4, 6),
                       (1, 4, 7), (2, 1, 3), (2, 1, 4), (3, 1, 4), (5, 4, 6),
                       (5, 4, 7), (6, 4, 7)]
    ethane.get_angles()
Exemple #23
0
def test_caffeine_molecular_weight():
    """ Testing impotant stuff here """
    caffeine = Molecule(atoms=['C'] * 8 + ['H'] * 10 + ['N'] * 4 + ['O'] * 2,
                        coordinates=[])
    mw = caffeine.get_molecular_weight()
    assert np.isclose(mw, 194.194, atol=0.01)
Exemple #24
0
def test_benzene_molecular_weight():
    """ Tests molecular weight calculation for benzene molecule """
    benzene = Molecule(read=benzene_xyz)
    mw = benzene.get_molecular_weight()
    assert np.isclose(mw, 78.11, atol=0.01)
Exemple #25
0
def main():
    parser = argparse.ArgumentParser(
        description="""
    =================================================
         __    __  ---- Ångström ----  __    __
      __/  \__/  \__      ╔═╗       __/  \__/  \__
     /  \__/  \__/  \     ╚═╝      /  \__/  \__/  \\
     \__/  \__/  \__/   ███████╗   \__/  \__/  \__/
     /  \__/  \__/  \  ██╔════██╗  /  \__/  \__/  \\
     \__/  \__/  \__/  ██║    ██║  \__/  \__/  \__/
     /  \__/  \__/  \  ██║██████║  /  \__/  \__/  \\
     \__/  \__/  \__/  ██║    ██║  \__/  \__/  \__/
        \__/  \__/     ██╝    ██╝     \__/  \__/
    =================================================
    Command-line molecular visualization.............
    =================================================
        """,
        epilog="""
    Example:
    > angstrom my_molecule.pdb
    would generate my_molecule.png file.
        """,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    # Positional arguments
    parser.add_argument('molecule',
                        type=str,
                        help='Molecule file (pdb / xyz) to read')

    # Optional arguments
    parser.add_argument('--read-config',
                        '-conf',
                        default='',
                        type=str,
                        metavar='',
                        help="Read config yaml file.")
    parser.add_argument('--exe',
                        '-x',
                        default='',
                        type=str,
                        metavar='',
                        help="Blender executable path")
    parser.add_argument('--video',
                        '-vid',
                        action='store_true',
                        default=False,
                        help="Render video.")
    parser.add_argument(
        '--rotate',
        '-rot',
        default=[0],
        type=int,
        metavar='',
        nargs=5,
        help=
        "Rotate molecule -> degrees x y z (axis) frames. (ex: 360 0 0 1 50)")
    parser.add_argument('--no-center',
                        action='store_true',
                        default=False,
                        help="Center molecule to origin.")
    parser.add_argument(
        '--model',
        '-m',
        default='default',
        type=str,
        metavar='',
        help=
        "Molecular representation model ([default] | ball_and_stick | space_filling | stick | surface)"
    )
    parser.add_argument(
        '--zoom',
        '-z',
        default=20,
        type=int,
        metavar='',
        help=
        "Image zoom, molecule gets smaller as zoom gets bigger (default: 20)")
    parser.add_argument(
        '--view',
        default='xy',
        type=str,
        metavar='',
        help="Camera view plane ([xy] | xz | yx | yz | zx | zy)")
    parser.add_argument('--distance',
                        '-d',
                        default=10,
                        type=int,
                        metavar='',
                        help="Camera distance from origin (default: 10)")
    parser.add_argument('--camera',
                        '-c',
                        default='ORTHO',
                        type=str,
                        metavar='',
                        help="Camera type ([ORTHO] | PERSP)")
    parser.add_argument('--light',
                        '-l',
                        default=2000.0,
                        type=float,
                        metavar='',
                        help="Light energy (default: 2000 W)")
    parser.add_argument(
        '--resolution',
        '-r',
        default='1920x1080',
        type=str,
        metavar='',
        help="Image resolution (WIDTHxHEIGHT) (default: 1920x1080)")
    parser.add_argument(
        '--bcolor',
        '-bc',
        default=None,
        type=float,
        metavar='',
        nargs='+',
        help=
        "Background color in RGBA (ex: 1.0 1.0 1.0 1.0 for white | default: transparent)"
    )
    parser.add_argument('--no-render',
                        '-nr',
                        action='store_true',
                        default=False,
                        help="Don't render the image (default: False)")
    parser.add_argument(
        '--save',
        '-s',
        default='',
        type=str,
        metavar='',
        help="Save .blend file [ex: molecule.blend] (default: don't save)")
    parser.add_argument('--verbose',
                        '-v',
                        action='store_true',
                        default=False,
                        help="Verbosity  (default: False)")

    args = parser.parse_args()
    # Set options --------------------------------------------------------------------------------------
    # Search for Blender executable if not given
    if args.exe == '':
        args.exe = search_blender_executable()

    blend = Blender()
    if args.read_config != '':
        print('Reading config file -> %s' % args.read_config)
        blend.read_config(args.read_config)
        blend.config['pdb']['filepath'] = args.molecule
        blend.config['img_file'] = '%s.png' % os.path.splitext(
            args.molecule)[0]
    else:
        img_file = os.path.join(
            os.getcwd(),
            '%s.png' % os.path.splitext(os.path.basename(args.molecule))[0])
        blend.configure(
            mol_file=args.molecule,
            img_file=img_file,
            executable=args.exe,
            model=args.model,
            save=args.save,
            render=(not args.no_render),
            verbose=args.verbose,
            camera_zoom=args.zoom,
            camera_type=args.camera.upper(),
            camera_view=args.view,
            camera_distance=args.distance,
            background_color=args.bcolor,
            light=args.light,
            resolution=[int(i) for i in args.resolution.split('x')])
    blend.config['pdb']['use_center'] = (not args.no_center)
    blend.print_config()
    if args.video:
        blend.config['pdb']['use_center'] = False
        if len(args.rotate) == 5:
            mol = Molecule(read=args.molecule)
            rot_axis = ([0, 0, 0], args.rotate[1:4])
            traj = rotation(mol,
                            args.rotate[4],
                            args.rotate[0],
                            rot_axis,
                            interpolation='linear')
        else:
            traj = Trajectory(read=args.molecule)
        render(traj,
               os.path.splitext(args.molecule)[0],
               renderer=blend,
               verbose=args.verbose)
    else:
        if os.path.splitext(args.molecule)[1] == '.pdb':
            blend.run()
        elif os.path.splitext(args.molecule)[1] == '.xyz':
            mol = Molecule(read=args.molecule)
            render(mol,
                   os.path.splitext(args.molecule)[0],
                   renderer=blend,
                   verbose=args.verbose)
        else:
            print('File format not supported for -> %s' % args.molecule)
def test_benzene_chemical_formula():
    """ Tests chemical formula for benzene molecule """
    benzene = Molecule(read=benzene_xyz)
    assert benzene.get_chemical_formula() == {'C': 6, 'H': 6}
Exemple #27
0
def build_nanocar(opts):
    """Builds Nanocar molecule."""
    chassis = Molecule(read=os.path.join(chassis_dir, '%s.xyz' %
                                         opts['chassis']))
    chassis.center([opts['center-x'], opts['center-y'], opts['center-z']])
    return mol2xyz(chassis)
def test_piyzaz_chemical_formula():
    """ Testing chemical formula for PIYZAZ in 111 and 222 packing"""
    piyzaz111 = Molecule(read=piyzaz111_xyz)
    assert piyzaz111.get_chemical_formula() == {'C': 8, 'Cd': 2}
    piyzaz222 = Molecule(read=piyzaz222_xyz)
    assert piyzaz222.get_chemical_formula() == {'C': 64, 'Cd': 16}
Exemple #29
0
def test_benzene_reflection_yz_plane_should_change_x_axis_position():
    mol = Molecule(read=benzene_xyz)
    mol.center([5, 0, 0])
    mol.reflect('yz')
    assert np.allclose(mol.get_center(), [-5, 0, 0])
Exemple #30
0
def test_benzene_reflection_xy_plane_should_not_change_orientation():
    mol = Molecule(read=benzene_xyz)
    mol.reflect('xy')
    assert np.allclose(mol.coordinates, benzene_coors)