Пример #1
0
class RunShelxl(ShelxNode):
    Input('INS', str)
    Input('HKL', str)
    Input('List', int,  optional=True)
    Input('Cycles', int)
    Input('DAMP', int)
    Input('Type', str, select=('CGLS', 'L.S.'))
    Output('RES', str)
    Output('LST', str)
    Output('FCF', str)
    Output('R1', float)

    def __init__(self, *args, **kwargs):
        super(RunShelxl, self).__init__(*args, **kwargs)
        self.p = None
        self.stdout = ''

    def run(self):
        super(RunShelxl, self).run()
        with open('__tmp__.ins', 'w') as fp:
            fp.write(self._INS)
        with open('__tmp__.hkl', 'w') as fp:
            fp.write(self._HKL)

        self.p = subprocess.Popen('shelxl {}'.format('__tmp__'), shell=True, stdout=subprocess.PIPE)
        while True:
            line = self.p.stdout.readline()
            if not line:
                break
            self.stdout += str(line)[1:]
        #os.waitpid(self.p.pid, 0)
        output = ''
        with open('__tmp__.res', 'r') as fp:
            output = fp.read()
        self._RES(output)
        with open('__tmp__.lst', 'r') as fp:
            output = fp.read()
        for line in output.splitlines():
            if line.startswith(' R1 ='):
                line = [i for i in line.split() if i]
                R1 = float(line[2])
                break
        self._R1(R1)
        self._LST(output)
        with open('__tmp__.fcf', 'r') as fp:
            output = fp.read()
        self._FCF(output)


        for file in os.listdir():
            if file.startswith('__tmp__'):
                os.remove(file)

    def report(self):
        r = super(RunShelxl, self).report()
        r['template'] = 'ProgramTemplate'
        r['stdout'] = self.stdout
        return r
Пример #2
0
class BreakPDB(CrystNode):
    Input('PDB', str)
    Output('Code', str)
    Output('R1', float)

    def run(self):
        for line in self._PDB.splitlines():
            if line.startswith('REMARK   3   R VALUE') and '(WORKING SET)' in line:
                line = [i for i in line[:-1].split() if i]
                r1 = line[-1]
            elif line.startswith('HEADER'):
                line = [i for i in line[:-1].split() if i]
                code = line[-1]
        self._Code(code)
        self._R1(r1)
Пример #3
0
class PlotNode2(Node):
    Input('XX', str)
    Output('YY', str)

    def __init__(self, *args, **kwargs):
        super(PlotNode2, self).__init__(*args, **kwargs)
        self.time = time.time()
        self.points = []
        self.counts = 0

    def check(self):
        t = time.time()
        if t - self.time > 3:
            self.time = t
            return True

    def run(self):
        super(PlotNode2, self).run()
        self.counts += 1
        self.points.append(
            (self.counts, (random.randint(5, 20), random.randint(5, 20), random.randint(5, 20), random.randint(5, 20))))

    def report(self):
        r = super(PlotNode2, self).report()
        r['template'] = 'PlotTemplate'
        r['points'] = self.points[:]
        r['keep'] = 'points'
        self.points = []
        return r
Пример #4
0
class CreateVector(MathNode):
    Input('X', float)
    Input('Y', float)
    Input('Z', float)
    Output('V', float, list=True)
    def run(self):
        self._Output(self._X, self._Y, self._Z)
Пример #5
0
class Add(MathNode):
    Input('F1', float)
    Input('F2', float)
    Output('Sum', float)

    def run(self):
        self._Sum(self._F1 + self._F2)
Пример #6
0
class MyNode(Node):
    Input('Int1', int)
    Output('Int2', int)

    def run(self):
        self._Int1
        self._Int2(self._Int1 + 1)
Пример #7
0
class RotateAbout(VectorNode):
    Input('Point', float, list=True)
    Input('PointOnAxis', float, list=True)
    Input('AxisDirection', float, list=True)
    Input('Degree', float)
    Output('RotatedPoint', float, list=True)

    def run(self):
        super(RotateAbout, self).run()

        point = self._Point
        angle = self._Degree
        axisDirection = self._AxisDirection
        axisOrigin = self._PointOnAxis

        t = angle * (pi / 180)
        x, y, z = point[0], point[1], point[2]
        a, b, c = axisOrigin[0], axisOrigin[1], axisOrigin[2]
        axisDirection /= norm(axisDirection)
        u, v, w = axisDirection[0], axisDirection[1], axisDirection[2]
        xx = (a * (v**2 + w**2) - u *
              (b * v + c * w - u * x - v * y - w * z)) * (
                  1 - cos(t)) + x * cos(t) + (-1 * c * v + b * w - w * y +
                                              v * z) * sin(t)
        yy = (b * (u**2 + w**2) - v *
              (a * u + c * w - u * x - v * y - w * z)) * (
                  1 - cos(t)) + y * cos(t) + (1 * c * u - a * w + w * x -
                                              u * z) * sin(t)
        zz = (c * (u**2 + v**2) - w *
              (a * u + b * v - u * x - v * y - w * z)) * (
                  1 - cos(t)) + z * cos(t) + (-1 * b * u + a * v - v * x +
                                              u * y) * sin(t)
        self._RotatedPoint([xx, yy, zz])
Пример #8
0
class Frac2Cart(CrystNode):
    Input('Position', float, list=True)
    Input('Cell', float, list=True)
    Output('Cart', float, list=True)

    def run(self):
        super(Frac2Cart, self).run()
        self._Cart(frac2cart(self._Position, self._Cell))
Пример #9
0
class FakeWorkNode(Node):
    Input('inp', object)
    Output('out', object)

    def run(self):
        print('Working @ {}'.format(str(self._inp)))
        time.sleep(random.randrange(1,5))
        print('Done')
Пример #10
0
class BreakAtom(CrystNode):
    Input('Atom', Atom)
    Output('Name', str)
    Output('Element', str)
    Output('frac', float, list=True)
    Output('cart', float, list=True)
    Output('ADP',float, list=True)
    Output('ADP_Flag', str)
    Output('Cell',float, list=True)

    def run(self):
        super(BreakAtom, self).run()
        atom = self._Atom
        # print(atom, atom.molecule.get_cell(degree=True))
        self._Name(atom.get_name())
        self._Element(atom.get_element())
        self._frac(atom.get_frac())
        self._cart(atom.get_cart())
        try:
            adp = atom.adp['cart_meas']
        except ADPDataError:
            adp = [0, 0, 0, 0, 0, 0]
        self._ADP(adp)
        self._ADP_Flag(atom.adp['flag'])
        self._Cell(atom.molecule.get_cell(degree=True))
Пример #11
0
class LinePlot(PlotNode):
    Input('Value', float)
    Output('Trigger', object)
    Output('Trigger', object)

    def setup(self):
        self.points = []

    def run(self):
        super(LinePlot, self).run()
        self.points.append((None, (self._Value, )))

    def report(self):
        r = super(LinePlot, self).report()
        r['template'] = 'PlotTemplate'
        r['points'] = self.points[:]
        self.points = []
        return r
Пример #12
0
class SelectAtom(CrystNode):
    Input('AtomList', Atom, list=True)
    Input('AtomName', str)
    Output('Atom', Atom)

    def run(self):
        super(SelectAtom, self).run()
        name = self._AtomName
        self._Atom([atom for atom in self._AtomList if atom.get_name() == name][0])
Пример #13
0
class IncrementNode(Node):
    Output('Integer', int)

    def setup(self):
        self.i = 0

    def run(self):
        self._Integer(self.i)
        self.i += 1
Пример #14
0
class DotProduct(VectorNode):
    Input('Vector1', float, list=True)
    Input('Vector2', float, list=True)
    Output('DotProduct', float, list=True)

    def run(self):
        super(DotProduct, self).run()
        v1 = self._Vector1
        v2 = self._Vector2
        self._DotProduct(v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2])
Пример #15
0
class Difference(VectorNode):
    Input('Vector1', float, list=True)
    Input('Vector2', float, list=True)
    Output('Difference', float, list=True)

    def run(self):
        super(Difference, self).run()
        v1 = self._Position1
        v2 = self._Position2
        self._Difference((v1[0] - v2[0]), (v1[1] - v2[1]), (v1[2] - v2[2]))
Пример #16
0
class VectorSum(VectorNode):
    Input('Vector1', float, list=True)
    Input('Vector2', float, list=True)
    Output('Sum', float, list=True)

    def run(self):
        super(VectorSum, self).run()
        v1 = self._Position1
        v2 = self._Position2
        self._Difference((v1[0] + v2[0]), (v1[1] + v2[1]), (v1[2] + v2[2]))
Пример #17
0
class Normalize(VectorNode):
    Input('Vector', float, list=True)
    Output('NVector', float, list=True)

    def run(self):
        super(Normalize, self).run()
        # v = self._Vector
        # d = (v[0]**2 + v[1]**2 + v[2]**2)**.5
        # self._NVector((v[0]/d, v[1]/d, v[2]/d))
        self._NVector(norm(self._Vector))
Пример #18
0
class CrossProduct(VectorNode):
    Input('Vector1', float, list=True)
    Input('Vector2', float, list=True)
    Output('XProduct', float, list=True)

    def run(self):
        super(CrossProduct, self).run()
        v1 = self._Vector1
        v2 = self._Vector2
        self._XProduct(v1[1]*v2[2]-v1[2]*v2[1], v1[2]*v2[0]-v1[0]*v2[2], v1[0]*v2[1]-v1[1]*v2[0])
Пример #19
0
class AMyNode(Node):
    Input('Inta', int)
    Input('Intb', int)
    Input('Int1', int, select=[1,2,3,4])
    Input('Int3', int, select=[1,2,3,4])
    Output('Int2', int)

    def run(self):
        self._Int1
        self._Int2(self._Int1 + 1)
Пример #20
0
class Distance(VectorNode):
    Input('Position1', float, list=True)
    Input('Position2', float, list=True)
    Output('Distance', float, )

    def run(self):
        super(Distance, self).run()
        v1 = self._Position1
        v2 = self._Position2
        d = (v1[0]-v2[0])**2 + (v1[1]-v2[1])**2 + (v1[2]-v2[2])**2
        self._Distance(d**.5)
Пример #21
0
class RunProgram(Node):
    """
    Node for calling an external program of given name and given command line arguments.
    Returns the program's return value and its stdout output.
    """
    Input('ProgramName', str)
    Input('Arguments', str)
    Output('ReturnValue', int)
    Output('StdOut', str)

    def run(self):
        programName = self._ProgramName
        args = [programName] + self._Arguments.split()
        r = 0
        try:
            out = subprocess.check_output(args, shell=True)
        except subprocess.CalledProcessError as e:
            out = ''
            r = e[-1]
        self._ReturnValue(r)
        self._StdOut(out)
Пример #22
0
class ReadAtoms(CrystNode):
    Input('FileName', str)
    Output('Atoms', Atom, list=True)

    def run(self):
        super(ReadAtoms, self).run()
        from lauescript.laueio.loader import Loader
        loader = Loader()
        loader.create(self._FileName)
        print('1')
        mol = loader.load('quickloadedMolecule')
        print('2')
        self._Atoms(mol.atoms)
Пример #23
0
class DotProduct(VectorNode):
    """
    Compute Dot product of two input Vectors.
    """
    Input('Vector1', float, list=True)
    Input('Vector2', float, list=True)
    Output('DotProduct', float, list=False)

    def run(self):
        super(DotProduct, self).run()
        v1 = self._Vector1
        v2 = self._Vector2
        self._DotProduct(v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2])
Пример #24
0
class ForEachAtomPair(ForLoop):
    Input('Start', Atom, list=True)
    Output('Atom1', Atom)
    Output('Atom2', Atom)

    # def __init__(self, *args, **kwargs):
    #     super(ForEachAtomPair, self).__init__(*args, **kwargs)

    def run(self):
        atoms = self._Start
        if self.fresh:
            self.x = 0
            self.y = 1
            self.end = len(atoms)-1
        self.fresh = False
        self._Atom1(atoms[self.x])
        self._Atom2(atoms[self.y])
        self.y += 1
        if self.y >= self.end:
            self.x += 1
            self.y = self.x+1
        if self.x >= self.end:
            self._Final(self._Start)
            self.done = True
Пример #25
0
class PlotBarsGrouped(PlotNode):
    Input('A', float)
    Input('B', float)
    Output('Trigger', object)

    def __init__(self, *args, **kwargs):
        super(PlotBarsGrouped, self).__init__(*args, **kwargs)
        self.data = []

    def run(self):
        super(PlotBarsGrouped, self).run()
        self.data.append((self._A, self._B))

    def report(self):
        r = super(PlotBarsGrouped, self).report()
        r['template'] = 'plotBarsGroupedTemplate'
        r['points'] = self.data[:]
        # r['keep'] = 'points'
        # self.data = []
        return r
Пример #26
0
class PDB2INS(CrystNode):
    Input('FileName', str)
    Input('Wavelength', float)
    Input('HKLF', int)
    Input('CELL', str)
    Input('SpaceGroup', str)
    Input('ANIS', bool)
    Input('MakeHKL', bool)
    Input('REDO', bool)
    Input('Z', int)
    Output('INS', str)
    Output('HKL', str)
    Output('PDB', str)

    def __init__(self, *args, **kwargs):
        super(PDB2INS, self).__init__(*args, **kwargs)
        self.stdout = ''

    def check(self):
        x = self.inputs['FileName'].isAvailable()
        return x

    def run(self):
        super(PDB2INS, self).run()
        opt =  ('pdb2ins',
                self._FileName,
                '-i',
                '-o __pdb2ins__.ins',
                ' -w '+str(self._Wavelength) if self._Wavelength else '',
                ' -h '+str(self._HKLF) if self._HKLF else '',
                ' -c '+str(self._CELL) if self._CELL else '',
                ' -s '+str(self._SpaceGroup) if self._SpaceGroup else '',
                ' -a ' if self._ANIS else '-a',
                ' -b ' if self._MakeHKL else '-b',
                ' -r ' if self._REDO else '',
                ' -z ' + str(self._Z) if self._Z else '',
                (' -d '+ self._FileName+'.sf') if not '@' in self._FileName else '')
        opt = ' '.join(opt)
        print(opt)
        # opt = [o for o in ' '.join(opt).split(' ') if o]
        # print(opt)
        self.p = subprocess.Popen(opt, shell=True, stdout=subprocess.PIPE)
        self.stdout = ''
        while True:
            line = self.p.stdout.readline()
            if not line:
                break
            self.stdout += str(line)[1:]
        # print('ran')
        self._INS(open('__pdb2ins__.ins', 'r').read())
        try:
            self._HKL(open('__pdb2ins__.hkl', 'r').read())
        except IOError:
            try:
                self._HKL(open('{}.hkl'.format(self._FileName), 'r').read())
            except IOError:
                self._HKL('')
        try:
            self._PDB(open('__pdb2ins__.pdb', 'r').read())
        except IOError:
            self._PDB(open('{}.pdb'.format(self._FileName), 'r').read())
        for file in os.listdir():
            if file.startswith('__pdb2ins__'):
                os.remove(file)

    def report(self):
        r = super(PDB2INS, self).report()
        r['stdout'] = self.stdout
        r['template'] = 'ProgramTemplate'
        return r
Пример #27
0
class Range(Node):
    Input('EndValue', int)
    Output('ValueList', int, list=True)
    def run(self):
        self._ValueList(list(range(self._EndValue)))
Пример #28
0
class RandomFloat(Node):
    Output('Float', float)

    def run(self):
        self._Float(random.random())
Пример #29
0
class Int2Str(Node):
    Input('Int', int)
    Output('Str', str)
    def run(self):
        self._Str(str(self._Int))