Example #1
0
    u.verbosity = args.verbosity

    nsteps = args.nsteps

    if nsteps:
        step = (args.max - args.min) / nsteps
        SpecRange = np.arange(args.min, args.max + 1, step)

    else:
        step = args.step
        SpecRange = np.arange(args.min, args.max + 1, step)
        nsteps = len(SpecRange)

    if u.verbosity >= 1:
        print
        print(u.banner(ch='#', length=80))
        print(title)
        print(u.banner(ch='#', length=80))
        print

    #
    # Recapitulation of input files
    #
    if u.verbosity >= 1:
        print(" > READING INPUT FILES...")
        print

    # if u.verbosity >= 2:
        print("   Dipole orientation file : %s" % infile)
        print("   Structure file          : %s" % structure)
        print
Example #2
0
def make_dipo(dipole, dipole_types, coords):

    dip_type = dipole[0]
    dip_s = np.sqrt(dipole_types[dip_type][0])

    dip_ori = dipole[1:]

    # Orient dipole along an interatomic axis
    if len(dip_ori) == 2:
        
        # -1 to adapt to Python numeration
        a = coords[dip_ori[0] - 1]
        b = coords[dip_ori[1] - 1]
        direction = (b - a) / np.linalg.norm(b - a)

        # dip = dip_s * direction
        dip = direction

        if u.verbosity >= 2:
            print("   Dipole oriented along %s." % ', '.join(u.compact_extended_list(dip_ori)))
        
    # Orient dipole along an interatomic axis and forming and angle
    # theta with the plane defined by 3 atoms
    elif len(dip_ori) == 4:

        # -1 to adapt to Python numeration
        a = coords[dip_ori[0] - 1]
        b = coords[dip_ori[1] - 1]
        c = coords[dip_ori[2] - 1]
        theta = dip_ori[3]

        # Generate a reference frame from point a, b, c
        # Our desired direction is b - a, i.e. the x axis
        # of this new ref frame. (see refframe function in
        # util.py
        ref = u.refframe(a, b, c)
        cartesian = np.eye(3)

        # Define transformation matrices
        T = np.dot(cartesian, ref.T)
        Ry = u.rot_mat_y(theta)

        # Ry is 4x4, reduce it to 3x3
        Ry = Ry[:3,:3]

        x = cartesian[0]

        direction = np.dot(x, Ry)
        direction = np.dot(direction, T.T)
        
        # dip = dip_s * direction
        dip = direction

        if u.verbosity >= 2:
            print("   Dipole oriented out of the plane defined by %s by %5.2f degrees." % \
            (', '.join(u.compact_extended_list(dip_ori[:-1])), theta))


    else:
        print(u.banner(text='ERROR', ch='#', length=80))
        print("Unrecognized number of parameters for dipole orientation.")
        print
        sys.exit()

    return dip
Example #3
0
def parse_input(infile):
    '''Returns a Dictionary with dipole types,
    and a list of tuples for points of application of the dipoles.
    The keys of dipole types dictionary are the flags set ny the user in the input.
    Each value is a tuple. The first element of the tuple is a list containing the
    Dipolar Strength, the Excitation energy and the damping. The second element of
    the tuple is a flag defining the type of polarizability to calculate (electric or
    magnetic). The third element of the tuple if present only for magnetic polarizabilities
    and it is the bj coefficient.

    For application points, the data are tuples of 3 elements.
    Each tuple contains, as first element, the center expressed in terms
    of atom indexes and, as second element, the weight to be applied on the
    first element of the list. As third element, we have a list of dipoles to be applied
    in that point. The dipole is described through a list containing the dipole
    type and its orientation, in terms of atomic indexes.'''

    u.checkfile(infile)

    type_counter = 0
    center_counter = 0

    dipole_types = {}
    centers = []

    with open(infile) as f:

        while True:

            line = f.readline()

            if not line:
                break

            if line.strip():

                if line.startswith('#'):
                    continue
                
                # Create Dipole Types Dictionary
                elif line.split()[0].lower() == 'type':
                    
                    type_counter += 1
                    type_flag = line.split()[1]

                    # Try to read TYPE definition without optional keyword
                    try:
                        dipole = map(float, line.split()[2:])
                        pol_type = 'ele'
                        dipole_types[type_flag] = (map(float, line.split()[2:]), pol_type)

                    # Read TYPE definition with optional keyword
                    except ValueError:
                        pol_type = line.split()[-2]
                        bj = float(line.split()[-1])
                        dipole_types[type_flag] = (map(float, line.split()[2:-2]), pol_type, bj)

                    type_counter += 1
    
                # Centers
                elif line.split()[0].lower() == 'center':
    
                    center_counter += 1
                    weight = float(line.split()[1])
                    atom_idx = u.extend_compact_list(line.split()[2:])

                    # Adjust indices to Python's numeration
                    atom_idx = map(lambda x: x - 1, atom_idx)

                    data = f.readline().strip()

                    # Retrieve dipoles applied in this center
                    dipoles = []
                    while True:

                        if not data or data.split()[0].lower() != 'dipole':
                            break 
                        
                        data = data.split()
                        dip_type = [data[1]]
                        dip_ori = data[2:]
                        
                        if len(dip_ori) == 2:
                            dip_ori = u.extend_compact_list(dip_ori)

                        elif len(dip_ori) > 2:
                            theta = float(dip_ori[-1])
                            dip_ori = u.extend_compact_list(dip_ori[:-1])
                            dip_ori = dip_ori + [theta]


                        dipole = dip_type + dip_ori
                        dipoles.append(dipole)

                        data = f.readline().strip()

                    centers.append((atom_idx, weight, dipoles))

                # Dipoles
                elif line.split()[0].lower() == 'dipole':
    
                    if center_counter == 0:
                        print(u.banner(text='ERROR', ch='#', length=80))
                        print
                        print(" You defined a DIPOLE before assigning it a CENTER in %s" % infile)
                        print
                        sys.exit()
    
                    # dipole_counter += 1
    
    if type_counter == 0:
        print(u.banner(text='ERROR', ch='#', length=80))
        print
        print(" No dipole TYPE has been defined in %s" % infile)
        print
        sys.exit()


    return dipole_types, centers